﻿using SRB.Tg.DrawingStandard;
//using SRB.Tg.NetDxf;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class DrawingAviationBridge
    {
        static System.Data.DataTable dtAviationBridge = new System.Data.DataTable();
        static System.Data.DataTable dtAviationBridgeInfo = new System.Data.DataTable();
        static System.Data.DataTable dtAviationBridgePileInfo = new System.Data.DataTable();
        static System.Data.DataTable dtAviationDXFInfo = new System.Data.DataTable();
        static System.Data.DataTable dtSection = new System.Data.DataTable();
        static List<Point2d> dxfPointLst = new List<Point2d>();
        static double slopeW = 0.025;
        static double slopeL = 0.125 * 0.5;
        static List<double> pierHLst = new List<double>();
        static bool isStartLeft = true;
        static double scale = 200;
        static double light_distinct = 0;
        static double bridgeSlope = 0;
        static double bridgeLength = 0;
        static double bridgeW = 300;
        static double refStartSt = 0;
        static double lightHeight = 2.04;
        static double dxf_scale = 100;
        static int startLightNo = 12;
        public DrawingAviationBridge(string bridgeId, double _scale = 1)
        {
            scale = _scale;
            string sqlBridge = "select * from vi_bridge where  id='" + bridgeId + "'";
            dtAviationBridgeInfo = MySqlHelper.ExecuteDataTable(sqlBridge, CommandType.Text);
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
                string sqlSpan = "select * from vi_aviation_bridge where  bridge_id='" + dtAviationBridgeInfo.Rows[0]["bridge_id"].ToString() + "' order by station asc";
                dtAviationBridge = MySqlHelper.ExecuteDataTable(sqlSpan, CommandType.Text);

                string sqlPile = "select * from vi_aviation_pile where  bridge_id='" + dtAviationBridgeInfo.Rows[0]["bridge_id"].ToString() + "'";
                dtAviationBridgePileInfo = MySqlHelper.ExecuteDataTable(sqlPile, CommandType.Text);

                string sqlDXF = "select * from busi_portable_dxfdata where  main_id='" + dtAviationBridgeInfo.Rows[0]["id"].ToString() + "'";
                dtAviationDXFInfo = MySqlHelper.ExecuteDataTable(sqlDXF, CommandType.Text);


                //主梁布跨信息
                string sqlSection = "select * from vi_aviation_section where  bridge_id='" + dtAviationBridgeInfo.Rows[0]["bridge_id"].ToString() + "' ";
                dtSection = MySqlHelper.ExecuteDataTable(sqlSection, CommandType.Text);

                dxf_scale = String.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["dxf_scale"].ToString()) ? 100 : double.Parse(dtAviationBridgeInfo.Rows[0]["dxf_scale"].ToString());
                startLightNo = String.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_start_number"].ToString()) ? 1 : int.Parse(dtAviationBridgeInfo.Rows[0]["light_start_number"].ToString());

            }

        }
        /// <summary>
        /// 立面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public static void PlotElevation(ref Database db, out Extents2d ext, Point2d insertPoint, out Point2d ptST)
        {
            ptST = insertPoint;
            pierHLst = new List<double>();
            List<Point2d> ptLst = new List<Point2d>();
            ext = new Extents2d(insertPoint, insertPoint);
            //string dxfPath = @"C:\Users\Administrator\Desktop\model\DL.dxf";
            //DxfManage dxfM = new DxfManage(dxfPath);
            //List<string> layerLst = dxfM.GetDxfLayersName();
            dxfPointLst = new List<Point2d>();
            //List<LineClass> lines = new List<LineClass>();
            #region 地面线添加
            //for (int i = 0; i < layerLst.Count; i++)
            //{
            //    string layerName = layerLst[i];
            //    List<LineClass> lst = dxfM.GetLwLineLayer(layerName);
            //    if (lst.Count > 0)
            //    {
            //        for (int j = 0; j < lst.Count; j++)
            //        {
            //            lines.Add(lst[j]);
            //        }
            //    }
            //}

            //for (int i = 0; i < lines.Count; i++)
            //{
            //    Point2d et = lines[i].EP;
            //    Point2d st = lines[i].SP;
            //    Point2d pe = dxfPointLst.Find(o => o.X == et.X && o.Y == et.Y);
            //    Point2d ps = dxfPointLst.Find(o => o.X == st.X && o.Y == st.Y);
            //    if (pe == Point2d.Origin)
            //        dxfPointLst.Add(et);
            //    if (ps == Point2d.Origin)
            //        dxfPointLst.Add(st);
            //}
            //dxfPointLst = dxfPointLst.OrderBy(o => o.X).ToList();
            double dxfScale = dxf_scale / 100.0;
            for (int i = 0; i < dtAviationDXFInfo.Rows.Count; i++)
            {
                double x = double.Parse(dtAviationDXFInfo.Rows[i]["x"].ToString())/ dxfScale;
                double y = double.Parse(dtAviationDXFInfo.Rows[i]["y"].ToString()) / dxfScale;
                Point2d pt = new Point2d(x, y);
                dxfPointLst.Add(pt);
            }
            if (dxfPointLst.Count > 0)
            {
                ext = new Extents2d(dxfPointLst[0], dxfPointLst[0]);
            }
            PLPloter.AddPolylineByPointList(db, dxfPointLst, ref ext, "H细线", false);
            #endregion

            double designHeight = 0, designReferHeight=0;
            double divCap = 0, divCapLast = 0, divHeight = 0;
            double startStation = 0;
            double light_start_station = 0;
            bridgeLength = 0;
            Line lineD = new Line();
            Line lineD0 = new Line();
            #region  设计线绘制
            Point2d dPt1 = Point2d.Origin;
            DataRow[] drsA0 = dtAviationBridge.Select(" name='A0'");
            DataRow[] drsA1 = dtAviationBridge.Select(" name='A1'");
            double leSeg = 0;
            List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();
            //Point2d dPt2 = Point2d.Origin;
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
             
                startStation = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station"].ToString()) * 100;
                bridgeSlope = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_slope"].ToString()) * 0.01;
                bridgeLength = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_length"].ToString()) * 100;
                refStartSt= string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["start_refer_station"].ToString())?0: double.Parse(dtAviationBridgeInfo.Rows[0]["start_refer_station"].ToString());
                lightHeight =string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_height"].ToString())?2.04: double.Parse(dtAviationBridgeInfo.Rows[0]["light_height"].ToString());
              
                //int num = (int)(bridgeLength / divCap);
                //num = (bridgeLength- divCap*num)>0 ? num : num + 1 ;
                designHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station_design_height"].ToString()) * 100;
                divCap = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_section_width"].ToString()) * 100;
                divHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_height"].ToString()) * 100;
                designReferHeight = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["start_station_refer_design_height"].ToString()) ? designHeight : double.Parse(dtAviationBridgeInfo.Rows[0]["start_station_refer_design_height"].ToString()) * 100;
                light_start_station = double.Parse(dtAviationBridgeInfo.Rows[0]["light_start_station"].ToString()) * 100;
                light_distinct = double.Parse(dtAviationBridgeInfo.Rows[0]["light_distinct"].ToString()) * 100;
         
                double startL = light_start_station - startStation;
                //if (startL % divCap != 0)
                //    light_start_station = (startStation + ((int)(startL / divCap)) * divCap) == startStation ? startStation + divCap * 2 : (startStation + ((int)(startL / divCap)) * divCap);

             
                int num = (int)(bridgeLength / divCap);
            
                divCapLast = bridgeLength - num * divCap;
                num = (bridgeLength - divCap * num) > 0 ? num + 1 : num;
           
                if (Math.Abs(dxfPointLst[dxfPointLst.Count - 1].X * 0.001 - startStation) > Math.Abs(dxfPointLst[0].X * 0.001 - startStation))
                {
                    isStartLeft = false;
                }
                else
                {
                    isStartLeft = true;
                }
                dPt1 = new Point2d(startStation, designHeight);
                //ext = new Extents2d(dPt1, dPt1);
                ptLst.Add(dPt1);
                Point2d dPt2 = dPt1;
                if (isStartLeft)
                {
                    dPt2 = dPt1.C2D(bridgeLength, -bridgeLength * bridgeSlope);
                    TextPloter.AddTitle(db, dPt1.C2D(bridgeLength * 0.5, 35 * scale), ref ext, "立面", "", scale);
                    ptST = dPt1;
                }
                else
                {
                    dPt2 = dPt1.C2D(-bridgeLength, -bridgeLength * bridgeSlope);
                    TextPloter.AddTitle(db, dPt1.C2D(-bridgeLength * 0.5, 35 * scale), ref ext, "立面", "", scale);
                    ptST = dPt2;
                }
                //设计线
                PLPloter.AddLine(db, dPt1, dPt2, ref ext, "H细线");
                #region 梁绘制
                #region 根据联绘制
                try
                {
                    if (dtSection.Rows.Count > 0)
                    {
                        //divCap = double.Parse(dtSection.Rows[0]["segment_length"].ToString()) * 100;
                        //divHeight = double.Parse(dtSection.Rows[0]["segment_length"].ToString()) * 100;
                        #region 
                        //List<double> spanLLst = new List<double>();
                     
                        string[] spanL = { "500" };
                        if (dtSection.Rows.Count > 0)
                        {
                            string span = dtSection.Rows[0]["span_height_segment"].ToString();
                            spanL = span.Split('+');
                        }
                        for (int j = 0; j < spanL.Length; j++)
                        {

                            string[] sp = spanL[j].Split('*');
                            double lenSpan = double.Parse(sp[0]);

                            double ht = 3;
                            if (sp[1].Contains("-"))
                            {
                                string[] heightLst = sp[1].Replace("(", "").Replace(")", "").Replace("（", "").Replace("）", "").Split('-');
                                double h1 = double.Parse(heightLst[0]);
                                double h2 = double.Parse(heightLst[1]);
                                Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, h1, h2);
                                tupleLst.Add(tu);
                            }
                            else
                            {
                                ht = double.Parse(sp[1]);
                                Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, ht, ht);
                                tupleLst.Add(tu);
                            }
                          
                        }

                        leSeg = 0;
                        for (int j = 0; j < tupleLst.Count; j++)
                        {
                            leSeg += tupleLst[j].Item1*100;
                           
                            PLPloter.AddLine(db, dPt1.C2D(leSeg- tupleLst[j].Item1 * 100, -tupleLst[j].Item2 * 100 - (leSeg - tupleLst[j].Item1*100)* bridgeSlope), dPt1.C2D(leSeg, -tupleLst[j].Item3 * 100 - leSeg* bridgeSlope), ref ext, "H细线");
                        }

                        #endregion
                    }
                    else
                    {
                        PLPloter.AddLine(db, dPt1.C2D(0, -divHeight), dPt2.C2D(0, -divHeight), ref ext, "H细线");
                    }
                }
                catch
                {
                    PLPloter.AddLine(db, dPt1.C2D(0, -divHeight), dPt2.C2D(0, -divHeight), ref ext, "H细线");
                }

                //PLPloter.AddLine(db, dPt1.C2D(0, -divHeight), dPt2.C2D(0, -divHeight), ref ext, "H细线");
                Point2d dpt1 = dPt1;
                Point2d dpt2 = dPt1.C2D(divCap, -divCap * bridgeSlope);
                PLPloter.AddLine(db, dPt1.C2D(0, -divHeight), dPt1.C2D(), ref ext, "H细线");
                if (divCapLast == 0)
                {
                    PLPloter.AddLine(db, dPt2.C2D(0, -divHeight), dPt2.C2D(), ref ext, "H细线");
                }
                lineD = new Line(dPt1.C3D(0, -divHeight), dPt2.C3D(0, -divHeight));
                lineD0 = new Line(dPt1.C3D(0, 0), dPt2.C3D(0, 0));
                #endregion
                double changeLen = 0, oldchangeLen=0;
                int changeNum = 1;
                bool isChange = false;
                changeLen = double.Parse(dtAviationBridge.Rows[changeNum]["length"].ToString()) * 100;
                string steel_tower_type = dtAviationBridge.Rows[changeNum]["steel_tower_type"].ToString();
                int no = 0;
                 for (int i = no; i <= num; i++)
                {
                  
                    if (drsA0.Length > 0)
                    {
                        if (divCap * (i + 1) > changeLen)
                        {
                            if (isChange)
                                isChange = false;
                            else
                                isChange = true;
                            if(changeNum< dtAviationBridge.Rows.Count-1)
                                changeNum++;
                            oldchangeLen = changeLen;
                            changeLen += double.Parse(dtAviationBridge.Rows[changeNum]["length"].ToString()) * 100;
                            no = i-1;
                        }
                        #region 高度计算
                        if (i < num)
                        {
                            if (isStartLeft)
                            {
                                dpt1 = dPt1.C2D(divCap * i, -divCap * i * bridgeSlope);
                                dpt2 = dPt1.C2D(divCap * (i + 1), -divCap * (i + 1) * bridgeSlope);

                            }
                            else
                            {
                                dpt1 = dPt1.C2D(-divCap * i, -divCap * i * bridgeSlope);
                                dpt2 = dPt1.C2D(-divCap * (i + 1), -divCap * (i + 1) * bridgeSlope);
                            }                          
                        }
                        else
                        {
                            if (isStartLeft)
                            {
                                if (divCap * (i) > bridgeLength)
                                {
                                    dpt1 = dPt1.C2D(divCap * (i-1), -(divCap * (i - 1)) * bridgeSlope);
                                    dpt2 = dPt1.C2D(divCap * (i - 1) + divCapLast, -(divCap * (i - 1) + divCapLast) * bridgeSlope);
                                }
                                else
                                {
                                    dpt1 = dPt1.C2D(divCap * (i), -(divCap * (i)) * bridgeSlope);
                                    dpt2 = dPt1.C2D(divCap * (i) + divCapLast, -(divCap * i + divCapLast) * bridgeSlope);
                                }

                            }
                            else
                            {
                                if (divCap * (i) > bridgeLength)
                                {
                                    dpt1 = dPt1.C2D(-divCap * (i-1), -(divCap * (i-1)) * bridgeSlope);
                                    dpt2 = dPt1.C2D(-divCap * (i-1) - divCapLast, -(divCap * (i - 1) + divCapLast) * bridgeSlope);
                                }
                                else
                                {
                                    dpt1 = dPt1.C2D(-divCap * (i), -(divCap * (i)) * bridgeSlope);
                                    dpt2 = dPt1.C2D(-divCap * (i) - divCapLast, -(divCap * i + divCapLast) * bridgeSlope);
                                }
                            }                            
                        }
                        leSeg = 0;
                        double leSeglast = 0;
                        double h1 = divHeight, h2 = divHeight;
                        for (int j = 0; j < tupleLst.Count; j++)
                        {
                            leSeg += tupleLst[j].Item1 * 100;
                           
                            double lenseg= tupleLst[j].Item1 * 100;
                            leSeglast = leSeg - lenseg;
                            double hh1 = tupleLst[j].Item2 * 100;
                            double hh2 = tupleLst[j].Item3 * 100;
                            if (hh1 == hh2)
                            {
                                h1 = divHeight;
                                h2 = divHeight;
                            }
                            else
                            {
                                if (i < num)
                                {
                                    h1 = hh1 + (hh2 - hh1) * (i * divCap - leSeglast) / lenseg;
                                    h2 = hh1 + (hh2 - hh1) * ((i + 1) * divCap - leSeglast) / lenseg;
                                }
                                else
                                {
                                    h1 = hh1 + (hh2 - hh1) * ((i-1) * divCap+divCapLast - leSeglast) / lenseg;
                                    h2 = hh1 + (hh2 - hh1) * ((i ) * divCap + divCapLast - leSeglast) / lenseg;
                                }
                            }
                            if (leSeg > i * divCap)
                                break;

                        }
                        #endregion

                        if (steel_tower_type == "2")
                        {
                            #region  y方案
                            if (isChange)
                            {
                                #region 
                                if (divCap * (i + 0.5) == oldchangeLen)
                                {
                                    if ((i - no) % 2 == 0)
                                    {
                                        if (divCapLast > 0)
                                        {
                                            if (i < num - 1)
                                            {
                                                PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                                PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                            }
                                        }
                                        else
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        if (divCapLast > 0)
                                        {
                                            if (i < num - 1)
                                            {
                                                PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                                PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                            }
                                        }
                                        else
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                        }
                                    }
                                }
                                if ((i-no) % 2 != 0)
                                {
                                    if (divCapLast > 0)
                                    {
                                        if (i < num - 1)
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                    }
                                }
                                else
                                {
                                    if (divCapLast > 0)
                                    {
                                        if (i < num - 1)
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                    }
                                }
                                #endregion
                            }
                            else
                            {
                                if (divCap * (i + 0.5) == oldchangeLen || (divCap * (i) == oldchangeLen && i != 0))
                                {
                                    if ((i - no) % 2 == 0)
                                    {
                                        if (divCapLast > 0)
                                        {
                                            if (i < num - 1)
                                            {
                                                PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                                PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                            }
                                        }
                                        else
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        if (divCapLast > 0)
                                        {
                                            if (i < num - 1)
                                            {
                                                PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                                PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                            }
                                        }
                                        else
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                        }
                                    }
                                }


                                if ((i - no) % 2 != 0)
                                {
                                    if (divCapLast > 0)
                                    {
                                        if (i < num - 1)
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                    }
                                }
                                else
                                {
                                    if (divCapLast > 0)
                                    {
                                        if (i < num - 1)
                                        {
                                            PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                            PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                        }
                                    }
                                    else
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                    }
                                }


                            }
                            #endregion
                        }
                        else
                        {
                            #region 方案 适合常规的
                            if (i % 2 != 0)
                            {
                                if (divCapLast > 0)
                                {
                                    if (i < num-1)
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                    }
                                }
                                else
                                {
                                    PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -h1), ref ext, "H细线");
                                    PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -h2), ref ext, "H细线");
                                }
                            }
                            else
                            {
                                if (divCapLast > 0)
                                {
                                    if (i < num-1)
                                    {
                                        PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                        PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                    }                                   
                                }
                                else
                                {
                                    PLPloter.AddLine(db, dpt1.C2D(0, -h1), dpt2.C2D(), ref ext, "H细线");
                                    PLPloter.AddLine(db, dpt2.C2D(0, -h2), dpt2.C2D(), ref ext, "H细线");
                                }
                            }
                            #endregion
                        }
                    }
                    if (drsA1.Length > 0)
                    {
                        if (divCap * (i + 1) > changeLen)
                        {
                            if (isChange)
                                isChange = false;
                            else
                                isChange = true;
                            if (changeNum < dtAviationBridge.Rows.Count - 1)
                                changeNum++;
                            oldchangeLen = changeLen;
                            changeLen += double.Parse(dtAviationBridge.Rows[changeNum]["length"].ToString()) * 100;
                        }
                        #region 坐标
                        if (i>0)
                        {
                            if (isStartLeft)
                            {
                                dpt1 = dPt1.C2D(divCapLast+divCap * (i-1), -(divCap * (i - 1) + divCapLast) * bridgeSlope);
                                dpt2 = dPt1.C2D(divCapLast+divCap * (i), -(divCap * (i)+ divCapLast) * bridgeSlope);

                            }
                            else
                            {
                                dpt1 = dPt1.C2D(-divCap * i- divCapLast, -(divCap * (i-1) + divCapLast )* bridgeSlope);
                                dpt2 = dPt1.C2D(-divCap * (i)- divCapLast, -(divCap * (i)+ divCapLast) * bridgeSlope);
                            }
                        }
                        else
                        {
                            if (isStartLeft)
                            {
                                dpt1 = dPt1.C2D(0, 0);
                                dpt2 = dPt1.C2D(divCapLast, -( divCapLast) * bridgeSlope);

                            }
                            else
                            {
                                dpt1 = dPt1.C2D(0, 0);
                                dpt2 = dPt1.C2D(- divCapLast, -(divCapLast) * bridgeSlope);
                            }
                        }
                        #endregion

                        if (i % 2 == 0)
                        {
                            PLPloter.AddLine(db, dpt1.C2D(), dpt2.C2D(0, -divHeight), ref ext, "H细线");
                            PLPloter.AddLine(db, dpt2.C2D(), dpt2.C2D(0, -divHeight), ref ext, "H细线");
                        }
                        else
                        {
                            PLPloter.AddLine(db, dpt1.C2D(0, -divHeight), dpt2.C2D(), ref ext, "H细线");
                            PLPloter.AddLine(db, dpt2.C2D(0, -divHeight), dpt2.C2D(), ref ext, "H细线");
                        }
                    }
                }
                #endregion


            }
            #endregion
            if (isStartLeft)
            {
                DimPloter.AddArrowTitle(db, dPt1.C3D(0, 4* scale), "降落", ref ext, 2.5, scale, true);
                DimPloter.AddArrowTitle(db, dPt1.C3D(bridgeLength, 800), "起飞", ref ext, 2.5, scale);
            }
            else
            {
                DimPloter.AddArrowTitle(db, dPt1.C3D(0, 4 * scale), "降落", ref ext, 2.5, scale);
                DimPloter.AddArrowTitle(db, dPt1.C3D(-bridgeLength, 4 * scale), "起飞", ref ext, 2.5, scale, true);
            }
            #region 绘制比例尺
            //double xDesign = startStation;
            //int index0 = dxfPointLst.FindIndex(o => o.X >= xDesign) > 0 ? dxfPointLst.FindIndex(o => o.X > xDesign) : dxfPointLst.Count - 2;
            //int index01 = dxfPointLst.FindLastIndex(o => o.X < xDesign) > 0 ? dxfPointLst.FindLastIndex(o => o.X < xDesign) : 0;
            //Line line20 = new Line(new Point3d(xDesign, 0, 0), new Point3d(xDesign, 1, 0));
            //Point3d ptDG = MathExtensions.GetIntersection(lineD, line20);


            double  dy =designHeight * 0.01 - designReferHeight * 0.01;
            Unit unit = Unit.Mile;
            int minheight = (int)dxfPointLst.Min(x => x.Y)  - (int)(dy * 100);
            int Maxheight = (int)dxfPointLst.Max(x => x.Y)- (int)(dy * 100);
            double hh =Math.Round((Maxheight - minheight)*0.01,0);
            int max0 = (int)(Maxheight * 0.01);
            int dx = Maxheight - max0 * 100;
            int max = (int)(designHeight * 0.01);
            int min = max-(int)hh;
            int h = max - min;

            Point2d scalePt = new Point2d(dxfPointLst[0].C2D(-800).X,min*100- dx);
            PlottingScale.AddPlottingScale(db, scalePt, ref ext, ((max0-h) * 100), ((int)((max0 + 5) * 100)), 2000, scale);
            #endregion

            //Line line1 = PL.GetLineSegment2dAt(0).CLine();
            double len = 0;

            #region 墩台绘制
            if (dtAviationBridge.Rows.Count > 0)
            {
                bool isLastTower = false;
                for (int i = 0; i < dtAviationBridge.Rows.Count; i++)
                {
                  
                    string name = dtAviationBridge.Rows[i]["name"].ToString();
                    len = double.Parse(dtAviationBridge.Rows[i]["x"].ToString()) * 100 - startStation;
                    int numS = (int)(len / divCap);
                    double x = startStation + divCap * numS + divCap * 0.5;
                    if (drsA0.Length>0&&i==0)
                    {
                        len = 0;
                    }
                    if (len >= bridgeLength)
                    {
                        isLastTower = true;
                        x = startStation + bridgeLength - divCap * 0.5;
                    }
                    //else
                    //   len = divCap * numS + divCap * 0.5;
                    if (len>0)
                        ptLst.Add(dPt1.C2D(len));
                    //if (i < dtAviationBridge.Rows.Count - 1)
                    //{
                  
                   
                    try
                    {
                     
                        //double x = double.Parse(dtAviationBridge.Rows[i]["x"].ToString()) * 100;
                       
                        //if (i == 0)
                        //    x = startStation;
                        int index = dxfPointLst.FindIndex(o => o.X >= x) >0? dxfPointLst.FindIndex(o => o.X >= x ) :0;

                        int index1 = dxfPointLst.FindLastIndex(o => o.X < x) > 0 ? dxfPointLst.FindLastIndex(o => o.X < x) : 0;
                        //Point3d dxfpt1 = new Point3d(dxfPointLst[index1].X/ dxfScale, dxfPointLst[index1].Y/dxfScale,0);
                        Line line1 = new Line(dxfPointLst[index1].C3D(), dxfPointLst[index].C3D());
                        if (index == 0)
                            line1 = new Line(dxfPointLst[0].C3D(), dxfPointLst[1].C3D());
                        Line line2 = new Line(new Point3d(x, 0, 0), new Point3d(x, 1, 0));
                        Point3d ptD = MathExtensions.GetIntersection(line1, line2);
                        if (name.Contains("P"))
                        {
                            double cushionH = double.Parse(dtAviationBridge.Rows[i]["hc_center_distance"].ToString()) * 100;
                            //slopeW = double.Parse(dtAviationBridge.Rows[i]["slope_w"].ToString());
                            slopeL = double.Parse(dtAviationBridge.Rows[i]["slope_l"].ToString());
                            #region 钢塔墩
                            double pCH = double.Parse(dtAviationBridge.Rows[i]["pile_top_height_correction"].ToString());
                            leSeg = 0;
                            for (int j = 0; j < tupleLst.Count; j++)
                            {
                                if(x-startStation<= leSeg)
                                {
                                    leSeg += tupleLst[j].Item1 * 100;
                                    lineD = new Line(dPt1.C3D(leSeg-tupleLst[j].Item1, -tupleLst[j].Item2 - (leSeg - tupleLst[j].Item1) * bridgeSlope), dPt1.C3D(leSeg, -tupleLst[j].Item3 - leSeg * bridgeSlope));
                                    break;
                                }
                            }
                              
                            Point3d ptG = MathExtensions.GetIntersection(lineD, line2);
                            double pierH = double.Parse(dtAviationBridge.Rows[i]["pier_height"].ToString())*100 - pCH * 100;
                            //double pierH = (ptG.Y - ptD.Y) - pCH * 100;
                            double pierH0 = (ptG.Y - ptD.Y);
                            pierHLst.Add(pierH);
                            #region 绘制墩柱
                            //Point2d cpt1 = ;
                            PLPloter.AddScaleLine(db, ptD.C2D(), ptG.C2D(), ref ext, "H中心线", 5);

                            string steel_tower_type = dtAviationBridge.Rows[i]["steel_tower_type"].ToString();
                            double yHeight = 0;
                            if (steel_tower_type == "0")
                                AviationStructure.DrawSteelTower(db, ptG.C2D(), ref ext, pierH, divCap, slopeL, bridgeSlope, dtAviationBridge.Rows[i], "H钢筋");
                            else if (steel_tower_type == "1")
                            {

                                AviationStructure.DrawGemstoneShapeSteelTower(db, ptG.C2D(), ref ext, pierH, divCap, slopeL, bridgeSlope, dtAviationBridge.Rows[i], "H钢筋", isLastTower);
                            }
                            else
                            {
                                AviationStructure.DrawYGemstoneShapeSteelTower(db, ptG.C2D(), ref ext, pierH, divCap, slopeL, bridgeSlope, dtAviationBridge.Rows[i], "H钢筋");
                                yHeight = double.Parse(dtAviationBridge.Rows[i]["yshape_height"].ToString()) * 100;
                            }
                            #endregion
                           
                            double bg = (ptG.Y - pierH)*0.01-dy;
                            DimPloter.DimBG(db, bg.ToString("0.000"), ptG.C3D(divCap * 0.5 + pierH * slopeL + 8 * scale, -pierH), ref ext, scale);
                            if (steel_tower_type == "2")
                            {
                                bg = (ptG.Y - yHeight) * 0.01 - dy;
                                DimPloter.DimBG(db, bg.ToString("0.000"), ptG.C3D(divCap * 0.5 + pierH * slopeL + 13 * scale, -yHeight), ref ext, scale);

                                DimPloter.DimAli(db, ptG.C3D(divCap * 0.5 + pierH * slopeL, -pierH), ptG.C3D(divCap * 0.5 + pierH * slopeL, -yHeight), ptG.C3D(divCap * 0.5 + pierH * slopeL + 10 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                            }
                            #region 绘制桩基(逻辑根据具体构件库绘制)
                            double pileH = 0;
                            if (dtAviationBridgePileInfo.Rows.Count > 0)
                            {
                                string capid = dtAviationBridge.Rows[i]["pile_cap_structural_id"].ToString();
                                string pileid = dtAviationBridge.Rows[i]["pile_structural_id"].ToString();
                                if (string.IsNullOrWhiteSpace(capid)) //无承台
                                {
                                    double pH = 0;
                                    double pH1 = 0;
                                    DataRow[] drs = dtAviationBridgePileInfo.Select("span_id='" + dtAviationBridge.Rows[i]["id"].ToString() + "'");
                                    Point2d pt1 = ptG.C2D(-divCap * 0.5 - (pierH- cushionH) * slopeL, -pierH);
                                    Point2d pt2 = ptG.C2D(divCap * 0.5 + (pierH - cushionH) * slopeL, -pierH);
                                    //桥型图暂时先默认桩长等长
                                    pileH = double.Parse(drs[0]["pile_length"].ToString());
                                    string is_add_steel_casing = drs[0]["is_add_steel_casing"].ToString();
                                    double htLen =0;
                                    double th= 0;
                                    double pileDia = double.Parse(drs[0]["dia"].ToString());
                                    PLPloter.AddPloy4(db, pt1, pileDia  * 0.5, pileDia  * 0.5, pileH * 100, ref ext, "H细线");
                                    pH = pileH;
                                    pH1 = double.Parse(drs[drs.Length - 1]["pile_length"].ToString()); 
                                    if (is_add_steel_casing == "1")
                                    {
                                        htLen = double.Parse(drs[0]["steel_casing_length"].ToString());
                                        th = double.Parse(drs[0]["steel_casing_thickness"].ToString());
                                        DimPloter.DimAli(db, pt1.C3D(), pt1.C3D(0, -pileH * 100), pt1.C3D(-(pileDia  * 0.5 + 10 * scale), 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                        PLPloter.AddPloy4(db, pt1, pileDia  * 0.5+ th, pileDia  * 0.5+ th, htLen * 100, ref ext, "H粗线");
                                        DimPloter.DimAli(db, pt1.C3D(), pt1.C3D(0, -htLen * 100), pt1.C3D(-(pileDia * 0.5 + 5 * scale), 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                    }
                                    else
                                    {
                                        if (pH1 != pH)
                                            DimPloter.DimAli(db, pt1.C3D(), pt1.C3D(0, -pileH * 100), pt1.C3D(-(pileDia * 0.5 + 5 * scale), 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                    }
                                    pileH = double.Parse(drs[drs.Length- 1]["pile_length"].ToString());
                                    pileDia = double.Parse(drs[drs.Length - 1]["dia"].ToString());
                                    is_add_steel_casing = drs[drs.Length - 1]["is_add_steel_casing"].ToString();
                                  
                                    PLPloter.AddPloy4(db, pt2, pileDia  * 0.5, pileDia  * 0.5, pileH * 100, ref ext, "H细线");
                                    pH = pileH > pH ? pH : pileH;
                                    if (is_add_steel_casing == "1")
                                    {
                                        htLen = double.Parse(drs[drs.Length - 1]["steel_casing_length"].ToString());
                                        th = double.Parse(drs[drs.Length - 1]["steel_casing_thickness"].ToString());
                                        DimPloter.DimBG(db, bg.ToString("0.000"), ptG.C3D(divCap * 0.5 + pierH * slopeL + 13 * scale, -yHeight), ref ext, scale);
                                        DimPloter.DimAli(db, ptG.C3D(divCap * 0.5 + pierH * slopeL, -pierH), ptG.C3D(divCap * 0.5 + pierH * slopeL, -yHeight), ptG.C3D(divCap * 0.5 + pierH * slopeL + 10 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                        DimPloter.DimAli(db, pt2.C3D(), pt2.C3D(0, -pileH * 100), ptG.C3D(divCap * 0.5 + pierH * slopeL + 10 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                        PLPloter.AddPloy4(db, pt2, pileDia  * 0.5 + th, pileDia  * 0.5 + th, htLen * 100, ref ext, "H粗线");
                                        DimPloter.DimAli(db, pt2.C3D(), pt2.C3D(0, -htLen * 100), ptG.C3D(divCap * 0.5 + pierH * slopeL + 5 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                    }
                                    else
                                    {
                                       
                                        if (steel_tower_type == "2")
                                        {
                                            DimPloter.DimBG(db, bg.ToString("0.000"), ptG.C3D(divCap * 0.5 + pierH * slopeL + 8 * scale, -yHeight), ref ext, scale);
                                            DimPloter.DimAli(db, ptG.C3D(divCap * 0.5 + pierH * slopeL, -pierH), ptG.C3D(divCap * 0.5 + pierH * slopeL, -yHeight), ptG.C3D(divCap * 0.5 + pierH * slopeL + 5 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                        }
                                         DimPloter.DimAli(db, pt2.C3D(), pt2.C3D(0, -pileH * 100), ptG.C3D(divCap * 0.5 + pierH * slopeL + 5 * scale, 0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                                    }
                                  
                                    DimPloter.DimAli(db, pt1.C3D(0, -pH*100), pt2.C3D(0, -pH * 100), pt2.C3D(0, -pH * 100 - 3.5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter,2);
                                }
                                else //存在承台
                                {
                                    //承台构件
                                    string sqlPileCap = "select * from busi_pile_cap_structural where  id='" + capid + "'";
                                    System.Data.DataTable dtPileCap = MySqlHelper.ExecuteDataTable(sqlPileCap, CommandType.Text);
                                    //桩构件
                                    string sqlPile = "select * from busi_pile_structural where  id='" + pileid + "'";
                                    System.Data.DataTable dtPile = MySqlHelper.ExecuteDataTable(sqlPile, CommandType.Text);

                                    DataRow[] drs = dtAviationBridgePileInfo.Select("span_id='" + dtAviationBridge.Rows[i]["id"].ToString() + "'");
                                    Point2d pt = ptG.C2D(0, -pierH);
                                    double capW = 1320, capL = 820, capH = 250;
                                    if (dtPileCap.Rows.Count > 0)
                                    {
                                        capW = double.Parse(dtPileCap.Rows[0]["pile_cap_width"].ToString());
                                        capL = double.Parse(dtPileCap.Rows[0]["pile_cap_length"].ToString());
                                        capH = double.Parse(dtPileCap.Rows[0]["pile_cap_height"].ToString());
                                    }
                                    PLPloter.AddPloy4(db, pt, capL * 0.5, capL * 0.5, capH, ref ext, "H钢筋");
                                    //桥型图暂时先默认桩长等长
                                    pileH = double.Parse(dtAviationBridgePileInfo.Rows[0]["pile_length"].ToString());
                                    double pileDia = double.Parse(dtAviationBridgePileInfo.Rows[0]["dia"].ToString());

                                    List<double> spanLLst = new List<double>();
                                    string[] spanL = { "500" };
                                    if (dtPile.Rows.Count > 0)
                                    {
                                        string span = dtPile.Rows[0]["span_l"].ToString();
                                        spanL = span.Split('+');
                                    }
                                    double totalL = 0;
                                    for (int j = 0; j < spanL.Length; j++)
                                    {
                                        if (spanL[j].Contains("*"))
                                        {
                                            string[] sp = spanL[j].Split('*');
                                            int m = int.Parse(sp[0]);
                                            double v = double.Parse(sp[1]);
                                            for (int n = 0; n < m; n++)
                                            {
                                                spanLLst.Add(v);
                                                totalL += v;
                                            }
                                        }
                                        else
                                        {
                                            if (double.Parse(spanL[j]) > 0)
                                            {
                                                spanLLst.Add(double.Parse(spanL[j]));
                                                totalL += double.Parse(spanL[j]);
                                            }
                                            else
                                            {
                                                spanLLst.Add(0);
                                            }
                                        }
                                    }

                                    double le = 0;
                                    for (int j = 0; j < spanLLst.Count; j++)
                                    {
                                        le += spanLLst[j];
                                        if (spanLLst[j] > 0)
                                        {
                                            if (j == 0)
                                            {
                                                PLPloter.AddPloy4(db, pt.C2D(-totalL * 0.5, -capH), pileDia * 0.1 * 0.5, pileDia * 0.1 * 0.5, pileH * 100, ref ext, "H钢筋");
                                                PLPloter.AddPloy4(db, pt.C2D(-totalL * 0.5 + le, -capH), pileDia * 0.1 * 0.5, pileDia * 0.1 * 0.5, pileH * 100, ref ext, "H钢筋");
                                            }
                                            else
                                            {
                                                PLPloter.AddPloy4(db, pt.C2D(-totalL * 0.5 + le, -capH), pileDia * 0.1 * 0.5, pileDia * 0.1 * 0.5, pileH * 100, ref ext, "H钢筋");
                                            }
                                        }
                                        else
                                        {
                                            PLPloter.AddPloy4(db, pt.C2D(0, -capH), pileDia * 0.1 * 0.5, pileDia * 0.1 * 0.5, pileH * 100, ref ext, "H钢筋");
                                        }
                                    }
                                }
                            }
                            #endregion

                            PLPloter.AddScaleLine(db, ptD.C2D(), ptG.C2D(0,- pierH - pileH * 100 - 4 * scale), ref ext, "H中心线", 5);
                            TextPloter.AddCirleDBText(db, ptG.C3D(0, -pierH - pileH * 100 - 4 * scale - 2.25 * scale), ref ext, dtAviationBridge.Rows[i]["name"].ToString(), scale, 2.5);
                            #endregion
                        }
                        else
                        {
                            #region 桥台
                            leSeg = 0;
                            for (int j = 0; j < tupleLst.Count; j++)
                            {
                                if (x-startStation <= leSeg)
                                {
                                    leSeg += tupleLst[j].Item1 * 100;
                                    lineD = new Line(dPt1.C3D(leSeg - tupleLst[j].Item1, -tupleLst[j].Item2 - (leSeg - tupleLst[j].Item1) * bridgeSlope), dPt1.C3D(leSeg, -tupleLst[j].Item3 - leSeg * bridgeSlope));
                                    break;
                                }
                            }

                            Point3d ptG = MathExtensions.GetIntersection(lineD, line2);
                            double pierH = (ptG.Y - ptD.Y);
                            //if (pierH < divHeight)
                            //{
                            //扩基示意
                            //}
                            PLPloter.AddPloy4(db, ptG.C2D(-divCap * 0.7, divHeight), divCap * 0.1, divCap * 0.1, divHeight+10, ref ext, "H粗线");
                            PLPloter.AddPloy4(db, ptG.C2D(-divCap * 0.3,-10), divCap * 0.7, divCap * 0.7, divHeight*1.2, ref ext, "H粗线");
                            PLPloter.AddLine(db, ptG.C2D(-divCap * 0.7, divHeight), ptG.C2D(-divCap * 0.3, divHeight), ref ext, "H细线");
                            PLPloter.AddLine(db, ptG.C2D(-divCap * 0.3,  divHeight), ptG.C2D(divCap * 0.4, -10), ref ext, "H细线");
                            PLPloter.AddScaleLine(db, ptD.C2D(), ptD.C2D(0, -15 * 100 - 3 * scale), ref ext, "H中心线", 5);
                            TextPloter.AddCirleDBText(db, ptD.C3D(0, -15 * 100 - 3 * scale - 2.25 * scale), ref ext, dtAviationBridge.Rows[i]["name"].ToString(), scale, 2.5);
                            #endregion
                        }
                      
                        //}
                    }
                    catch(Exception ex)
                    { }

                }
            }
            #endregion

            ptLst.Add(dPt1.C2D(bridgeLength));

            #region 灯绘制
            int numL = (int)((bridgeLength - (light_start_station - startStation)) / light_distinct);
            for (int i = 0; i <= numL; i++)
            {
                double x = light_start_station + light_distinct * i;
             
                int index = dxfPointLst.FindIndex(o => o.X >= x) > 0 ? dxfPointLst.FindIndex(o => o.X < x ) : dxfPointLst.Count - 2;
                int index1 = dxfPointLst.FindLastIndex(o => o.X < x ) > 0 ? dxfPointLst.FindLastIndex(o => o.X < x) : 0;
                Line line1 = new Line(dxfPointLst[index1].C3D(), dxfPointLst[index].C3D());
                if (index1 == 0)
                    line1 = new Line(dxfPointLst[0].C3D(), dxfPointLst[1].C3D());

                Line line2 = new Line(new Point3d(x, 0, 0), new Point3d(x, 1, 0));
                Point3d ptD = MathExtensions.GetIntersection(line1, line2);
                Point3d ptG = MathExtensions.GetIntersection(lineD0, line2);

                PLPloter.AddSolidCircle(db, ptG.C2D(0, lightHeight * 100), ref ext, 50, "H粗线");
                PLPloter.AddLine(db, ptG.C2D(), ptG.C2D(0, lightHeight * 100), ref ext, "H粗线");
            }
            #endregion

            bridgeLength = (ptLst[ptLst.Count - 1].X - ptLst[0].X);
            #region 添加标注
            DimPloter.DimAli(db, ptLst[0].C3D(), ptLst[ptLst.Count - 1].C3D(), ptLst[0].C2D(0, 20 * scale).C3D(), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            for (int i = 1; i < ptLst.Count; i++)
            {
                DimPloter.DimAli(db, ptLst[i - 1].C3D(), ptLst[i].C3D(), ptLst[0].C2D(0, 15 * scale).C3D(), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            }
            if (isStartLeft)
            {
                PLPloter.AddScaleLine(db, ptLst[0].C2D(0, 20 * scale), ptLst[0].C2D(0, 35 * scale), ref ext, "H细线", 5);
                TextPloter.AddDBText(db, ptLst[0].C3D(-1*scale, 20 * scale), ref ext, "起点桩号", scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
                //TextPloter.AddDBText(db, ptLst[0].C3D(3 * scale, 21.5 * scale), ref ext, "K+" + (startStation / 100).ToString(), scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
                
                TextPloter.AddDBText(db, ptLst[0].C3D(4 * scale, 21.5 * scale), ref ext, "K+" + (refStartSt / 100).ToString(), scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
            }
            else
            {
                PLPloter.AddScaleLine(db, ptLst[ptLst.Count - 1].C2D(0, 20 * scale), ptLst[ptLst.Count - 1].C2D(0, 35 * scale), ref ext, "H细线", 5);
                TextPloter.AddDBText(db, ptLst[ptLst.Count - 1].C3D(1 * scale, 20 * scale), ref ext, "起点桩号", scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
                //TextPloter.AddDBText(db, ptLst[ptLst.Count - 1].C3D(3 * scale, 21.5 * scale), ref ext, "K+" + (startStation / 100).ToString(), scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
                TextPloter.AddDBText(db, ptLst[ptLst.Count - 1].C3D(-4 * scale, 21.5 * scale), ref ext, "K+" + (refStartSt / 100).ToString(), scale, 2.5, Extensions.curFont, GeTools.DegreeToRadian(90));
            }
            #endregion
        }

        
        /// <summary>
        /// 平面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public static void PlotPlan(ref Database db, ref Extents2d ext, Point2d insertPoint)
        {
            //ext = new Extents2d(insertPoint, insertPoint);
            List<Point2d> ptLst = new List<Point2d>();
            #region  中心线绘制
            bool isStartLeft = true;
            double designHeight = 0;
            double divCap = 0, divCapLast = 0;
            double startStation = 0;
            Point2d dPt1 = Point2d.Origin;
            DataRow[] drsA0 = dtAviationBridge.Select(" name='A0'");
            DataRow[] drsA1 = dtAviationBridge.Select(" name='A1'");
            double leSeg = 0;
            List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
                startStation = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station"].ToString()) * 100;
                double bridgeSlope = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_slope"].ToString()) * 0.01;
                double bridgeLength = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_length"].ToString()) * 100;

                divCap = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_section_width"].ToString()) * 100;
                //divHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_height"].ToString()) * 100;
                double light_start_station = double.Parse(dtAviationBridgeInfo.Rows[0]["light_start_station"].ToString()) * 100;
                light_distinct = double.Parse(dtAviationBridgeInfo.Rows[0]["light_distinct"].ToString()) * 100;
                int num = (int)(bridgeLength / divCap);
               
                divCapLast = bridgeLength - num * divCap;
                num = (bridgeLength - divCap * num) > 0 ? num + 1 : num;


                dPt1 = new Point2d(startStation, insertPoint.Y);
                ptLst.Add(dPt1);
                //ext = new Extents2d(insertPoint, insertPoint);
                Point2d dPt2 = dPt1;

                try
                {
                    if (dtSection.Rows.Count > 0)
                    {
                        divCap = double.Parse(dtSection.Rows[0]["segment_length"].ToString()) * 100;                       
                        #region 
                        //List<double> spanLLst = new List<double>();

                        string[] spanL = { "500" };
                        if (dtSection.Rows.Count > 0)
                        {
                            string span = dtSection.Rows[0]["span_width_segment"].ToString();
                            spanL = span.Split('+');
                        }
                        for (int j = 0; j < spanL.Length; j++)
                        {

                            string[] sp = spanL[j].Split('*');
                            double lenSpan = double.Parse(sp[0]);

                            double wt = 3;
                            if (sp[1].Contains("-"))
                            {
                                string[] widthLst = sp[1].Replace("(", "").Replace(")", "").Replace("（", "").Replace("）", "").Split('-');
                                double w1 = double.Parse(widthLst[0]);
                                double w2 = double.Parse(widthLst[1]);
                                Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, w1, w2);
                                tupleLst.Add(tu);
                            }
                            else
                            {
                                wt = double.Parse(sp[1]);
                                Tuple<double, double, double> tu = new Tuple<double, double, double>(lenSpan, wt, wt);
                                tupleLst.Add(tu);
                            }

                        }

                        leSeg = 0;
                        double lightx = light_start_station - startStation;
                        int numL = (int)((bridgeLength - (light_start_station - startStation)) / light_distinct);
                        int startNum = 0;
                        for (int j = 0; j < tupleLst.Count; j++)
                        {
                            leSeg += tupleLst[j].Item1 * 100;
                            PLPloter.AddLine(db, dPt1.C2D(leSeg - tupleLst[j].Item1 * 100, tupleLst[j].Item2 * 100 * 0.5), dPt1.C2D(leSeg, tupleLst[j].Item3 * 100 * 0.5), ref ext, "H细线");
                            PLPloter.AddLine(db, dPt1.C2D(leSeg - tupleLst[j].Item1 * 100, -tupleLst[j].Item2 * 100 * 0.5), dPt1.C2D(leSeg, -tupleLst[j].Item3 * 100 * 0.5), ref ext, "H细线");
                            int numSL = (int)((leSeg - lightx) / light_distinct);

                           

                            for (int i = startNum; i <= numL; i++)
                            {
                                if (i <= numSL)
                                {
                                    if (tupleLst[j].Item3 * 100 - tupleLst[j].Item2 * 100 > 0)
                                    {
                                        double wL = tupleLst[j].Item2 * 100 + ((leSeg - lightx - i * light_distinct) / (tupleLst[j].Item1 * 100)) * (tupleLst[j].Item3 * 100 - tupleLst[j].Item2 * 100);
                                        double addW = (450 - wL) * 0.5;
                                        if (wL < 450)//桥宽小于4.5m灯距，焊接扩展
                                        {
                                            Point2d dlPt1 = dPt1.C2D(lightx + i * light_distinct, wL * 0.5);
                                            Point2d dlPt2 = dPt1.C2D(lightx + i * light_distinct, -wL * 0.5);
                                            double count = (lightx + i * light_distinct) / divCap;
                                            double divnum = (int)(count);
                                            double le = Math.Abs(Math.Round(count - (int)(count), 1));
                                            if (le > 0)
                                            {
                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, wL * 0.5), dPt1.C2D(divCap * divnum, wL * 0.5+addW), ref ext, "H细线");
                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum+1), wL * 0.5), dPt1.C2D(divCap * (divnum + 1), wL * 0.5+ addW), ref ext, "H细线");
                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, wL * 0.5+addW), dPt1.C2D(divCap * (divnum + 1), wL * 0.5+ addW), ref ext, "H细线");

                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, -wL * 0.5), dPt1.C2D(divCap * divnum, -wL * 0.5 - addW), ref ext, "H细线");
                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1), -wL * 0.5), dPt1.C2D(divCap * (divnum + 1), -wL * 0.5 - addW), ref ext, "H细线");
                                                //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, -wL * 0.5 - addW), dPt1.C2D(divCap * (divnum + 1), -wL * 0.5 - addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, wL * 0.5), dPt1.C2D(divCap * divnum - 0.904, wL * 0.5 + addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1) + 0.596, wL * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, wL * 0.5 + addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, wL * 0.5 + addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, wL * 0.5 + addW), ref ext, "H细线");

                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5), dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5 - addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5 - addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5 - addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5 - addW), ref ext, "H细线");

                                            }
                                            else
                                            {
                                                PLPloter.AddLine(db, dlPt1.C2D(-divCap * 0.5, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt1.C2D(divCap * 0.5, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt1.C2D(0, 0), dlPt1.C2D(0, addW), ref ext, "H细线");

                                                PLPloter.AddLine(db, dlPt2.C2D(-divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt2.C2D(divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt2.C2D(0, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                            }
                                        }
                                        
                                    }
                                    else
                                    {
                                        double wL = tupleLst[j].Item2 * 100 ;
                                        double addW = (450 - wL) * 0.5;
                                        if (wL < 450)//桥宽小于4.5m灯距，焊接扩展
                                        {
                                            Point2d dlPt1 = dPt1.C2D(lightx + i * light_distinct, wL * 0.5);
                                            Point2d dlPt2 = dPt1.C2D(lightx + i * light_distinct, -wL * 0.5);
                                            double count = (lightx + i * light_distinct) / divCap;
                                            double divnum = (int)(count);
                                            double le = Math.Abs(Math.Round(count - (int)(count), 1));
                                            if (le > 0)
                                            {
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum-0.904, wL * 0.5), dPt1.C2D(divCap * divnum - 0.904, wL * 0.5 + addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1)+0.596, wL * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, wL * 0.5 + addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, wL * 0.5 + addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, wL * 0.5 + addW), ref ext, "H细线");

                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5), dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5 - addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5 - addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -wL * 0.5 - addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, -wL * 0.5 - addW), ref ext, "H细线");
                                            }
                                            else
                                            {
                                                PLPloter.AddLine(db, dlPt1.C2D(-divCap * 0.5, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt1.C2D(divCap * 0.5, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt1.C2D(0, 0), dlPt1.C2D(0, addW), ref ext, "H细线");

                                                PLPloter.AddLine(db, dlPt2.C2D(-divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt2.C2D(divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                                PLPloter.AddLine(db, dlPt2.C2D(0, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    startNum = numSL + 1;
                                    break;
                                }
                               
                            }

                        }

                        #endregion
                    }
                    else
                    {
                        PLPloter.AddLine(db, dPt1.C2D(0, divCap * 0.5), dPt2.C2D(0, divCap * 0.5), ref ext, "H细线");
                        PLPloter.AddLine(db, dPt1.C2D(0, -divCap * 0.5), dPt2.C2D(0, -divCap * 0.5), ref ext, "H细线");
                        if (bridgeW < 450)//桥宽小于4.5灯距，焊接扩展
                        {
                            double lightx = light_start_station - startStation;
                            double addW = (450 - bridgeW) * 0.5;
                            int numL = (int)((bridgeLength - (light_start_station - startStation)) / light_distinct);
                            for (int i = 0; i <= numL; i++)
                            {                               
                                Point2d dlPt1 = dPt1.C2D(lightx+i*light_distinct, divCap * 0.5);
                                Point2d dlPt2 = dPt1.C2D(lightx + i * light_distinct, -divCap * 0.5);
                                //PLPloter.AddLine(db, dlPt1.C2D(-divCap * 0.5, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                //PLPloter.AddLine(db, dlPt1.C2D( divCap * 0.5, 0),  dlPt1.C2D(0, addW), ref ext, "H细线");
                                //PLPloter.AddLine(db, dlPt1.C2D(0, 0), dlPt1.C2D(0, addW), ref ext, "H细线");

                                //PLPloter.AddLine(db, dlPt2.C2D(-divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                //PLPloter.AddLine(db, dlPt2.C2D(divCap * 0.5, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                //PLPloter.AddLine(db, dlPt2.C2D(0, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                double count = (lightx + i * light_distinct) / divCap;
                                double divnum = (int)(count);
                                double le = Math.Abs(Math.Round(count - (int)(count), 1));
                                if (le > 0)
                                {
                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, divCap * 0.5), dPt1.C2D(divCap * divnum, divCap * 0.5 + addW), ref ext, "H细线");
                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1), divCap * 0.5), dPt1.C2D(divCap * (divnum + 1), divCap * 0.5 + addW), ref ext, "H细线");
                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, divCap * 0.5 + addW), dPt1.C2D(divCap * (divnum + 1), divCap * 0.5 + addW), ref ext, "H细线");

                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, -divCap * 0.5), dPt1.C2D(divCap * divnum, -divCap * 0.5 - addW), ref ext, "H细线");
                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1), -divCap * 0.5), dPt1.C2D(divCap * (divnum + 1), -divCap * 0.5 - addW), ref ext, "H细线");
                                    //PLPloter.AddLine(db, dPt1.C2D(divCap * divnum, -divCap * 0.5 - addW), dPt1.C2D(divCap * (divnum + 1), -divCap * 0.5 - addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, divCap * 0.5), dPt1.C2D(divCap * divnum - 0.904, divCap * 0.5 + addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1) + 0.596, divCap * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, divCap * 0.5 + addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, divCap * 0.5 + addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, divCap * 0.5 + addW), ref ext, "H细线");

                                    PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -divCap * 0.5), dPt1.C2D(divCap * divnum - 0.904, -divCap * 0.5 - addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dPt1.C2D(divCap * (divnum + 1) + 0.596, -divCap * 0.5), dPt1.C2D(divCap * (divnum + 1) + 0.596, -divCap * 0.5 - addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dPt1.C2D(divCap * divnum - 0.904, -divCap * 0.5 - addW), dPt1.C2D(divCap * (divnum + 1) + 0.596, -divCap * 0.5 - addW), ref ext, "H细线");
                                }
                                else
                                {
                                    PLPloter.AddLine(db, dlPt1.C2D(-divCap, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dlPt1.C2D(divCap, 0), dlPt1.C2D(0, addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dlPt1.C2D(0, 0), dlPt1.C2D(0, addW), ref ext, "H细线");

                                    PLPloter.AddLine(db, dlPt2.C2D(-divCap, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dlPt2.C2D(divCap, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                    PLPloter.AddLine(db, dlPt2.C2D(0, 0), dlPt2.C2D(0, -addW), ref ext, "H细线");
                                }
                            }
                        }
                    }
                }
                catch
                {
                    PLPloter.AddLine(db, dPt1.C2D(0, divCap * 0.5), dPt2.C2D(0, divCap * 0.5), ref ext, "H细线");
                    PLPloter.AddLine(db, dPt1.C2D(0, -divCap * 0.5), dPt2.C2D(0, -divCap * 0.5), ref ext, "H细线");
                }
                if (isStartLeft)
                {
                    dPt2 = dPt1.C2D(bridgeLength, 0);
                    TextPloter.AddDBText(db, dPt2.C3D(100), ref ext, "跑道中线延长线", scale, 2.5, Extensions.curFont, 0);
                    PLPloter.AddLine(db, dPt1.C2D(0), dPt2.C2D(20 * scale, 0), ref ext, "H中心线");

                    TextPloter.AddTitle(db, dPt1.C2D(bridgeLength * 0.5, 13 * scale), ref ext, "平面", "", scale);
                }
                else
                {
                    dPt2 = dPt1.C2D(-bridgeLength, 0);
                    TextPloter.AddDBText(db, dPt1.C3D(100), ref ext, "跑道中线延长线", scale, 2.5, Extensions.curFont, 0);
                    PLPloter.AddLine(db, dPt1.C2D(20 * scale), dPt2.C2D(0, 0), ref ext, "H中心线");
                    TextPloter.AddTitle(db, dPt1.C2D(-bridgeLength * 0.5, 13 * scale), ref ext, "平面", "", scale);
                }
              
                #region 外边沿旧版本 不考虑变宽 废弃
                //PLPloter.AddLine(db, dPt1.C2D(0, divCap * 0.5), dPt2.C2D(0, divCap * 0.5), ref ext, "H细线");
                //PLPloter.AddLine(db, dPt1.C2D(0, -divCap * 0.5), dPt2.C2D(0, -divCap * 0.5), ref ext, "H细线");
                #endregion

            }
            #endregion
            double len = 0;
            if (dtAviationBridge.Rows.Count > 0)
            {
                for (int i = 0; i < dtAviationBridge.Rows.Count; i++)
                {
                    leSeg = 0;
                   
                    //len += double.Parse(dtAviationBridge.Rows[i]["length"].ToString()) * 100;
                    len = double.Parse(dtAviationBridge.Rows[i]["x"].ToString()) * 100 - startStation;
                   
                    //int numS = (int)(len / divCap);
                    int numS = (int)(len / divCap);
                    double x = startStation + divCap * numS + divCap * 0.5;
                    if (drsA0.Length > 0 && i == 0)
                    {
                        len = 0;
                    }
                    //else
                    //    len = divCap * numS + divCap * 0.5;

                    if (len >= bridgeLength)
                    {
                        x = startStation + bridgeLength - divCap * 0.5;
                    }
                    if (len > 0)
                        ptLst.Add(dPt1.C2D(len));
                    //len = divCap * numS + divCap * 0.5;
                    //ptLst.Add(dPt1.C2D(len));
                    //double x = double.Parse(dtAviationBridge.Rows[i]["x"].ToString()) * 100;
                    //if (i < dtAviationBridge.Rows.Count - 1)
                    //{
                    string name = dtAviationBridge.Rows[i]["name"].ToString();
                    double bw = divCap;
                    if (tupleLst.Count > 0)
                    {
                        bw = tupleLst[0].Item2*100;
                        bridgeW= bw;
                    }
                    if (name.Contains("P"))
                    {
                        double cushionH = double.Parse(dtAviationBridge.Rows[i]["hc_center_distance"].ToString()) * 100;
                        slopeW = double.Parse(dtAviationBridge.Rows[i]["slope_w"].ToString());
                        slopeL = double.Parse(dtAviationBridge.Rows[i]["slope_l"].ToString());
                        Point2d pt = new Point2d(startStation + len, insertPoint.Y);
                       
                      
                        if (tupleLst.Count > 0)
                        {
                            try
                            {
                                bw = tupleLst[0].Item2*100;
                                for (int j = 0; j < tupleLst.Count; j++)
                                {
                                    leSeg += tupleLst[j].Item1 * 100;
                                    if (len < leSeg)
                                    {
                                      
                                        if (j > 0)
                                            bw = tupleLst[j].Item2 * 100 + ((len - tupleLst[j - 1].Item1 * 100) / tupleLst[j].Item1 * 100) * (tupleLst[j].Item3 * 100 - tupleLst[j].Item2 * 100);
                                        else
                                            bw = tupleLst[j].Item2 * 100 + (len / tupleLst[j].Item1 * 100) * (tupleLst[j].Item3 * 100 - tupleLst[j].Item2 * 100);
                                        break;
                                    }
                                }
                            }
                            catch { }
                        }
                        double pierH = pierHLst[0];
                        if (drsA0.Length>0)
                           pierH = pierHLst[i-1];
                        else
                            pierH = pierHLst[i];
                        double pCH = double.Parse(dtAviationBridge.Rows[i]["pile_top_height_correction"].ToString());
                        //double W = divCap * 0.5 + (pierH - pCH * 100) * slopeW;
                        //double L = divCap * 0.5 + (pierH - pCH * 100) * slopeL;

                        //PLPloter.AddSolidCircle(db, pt.C2D(-divCap * 0.5, divCap * 0.5).C2D(-W * 0.5, L * 0.5), ref ext, 50);
                        //PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, divCap * 0.5).C2D(-W * 0.5, L * 0.5), pt.C2D(-divCap * 0.5, divCap * 0.5), ref ext, "H细线");
                        //PLPloter.AddSolidCircle(db, pt.C2D(divCap * 0.5, divCap * 0.5).C2D(W * 0.5, L * 0.5), ref ext, 50);
                        //PLPloter.AddLine(db, pt.C2D(divCap * 0.5, divCap * 0.5).C2D(W * 0.5, L * 0.5), pt.C2D(divCap * 0.5, divCap * 0.5), ref ext, "H细线");
                        //PLPloter.AddSolidCircle(db, pt.C2D(-divCap * 0.5, -divCap * 0.5).C2D(-W * 0.5, -L * 0.5), ref ext, 50);
                        //PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, -divCap * 0.5).C2D(-W * 0.5, -L * 0.5), pt.C2D(-divCap * 0.5, -divCap * 0.5), ref ext, "H细线");
                        //PLPloter.AddSolidCircle(db, pt.C2D(divCap * 0.5, -divCap * 0.5).C2D(W * 0.5, -L * 0.5), ref ext, 50);
                        //PLPloter.AddLine(db, pt.C2D(divCap * 0.5, -divCap * 0.5).C2D(W * 0.5, -L * 0.5), pt.C2D(divCap * 0.5, -divCap * 0.5), ref ext, "H细线");

                        double W = (pierH - pCH * 100- cushionH) * slopeL*2;
                        double L =  (pierH - pCH * 100- cushionH) * slopeW * 2;

                        PLPloter.AddSolidCircle(db, pt.C2D(-divCap * 0.5, bw * 0.5).C2D(-W * 0.5, L * 0.5), ref ext, 50);
                        PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, bw * 0.5).C2D(-W * 0.5, L * 0.5), pt.C2D(-divCap * 0.5, bw * 0.5), ref ext, "H细线");
                        PLPloter.AddSolidCircle(db, pt.C2D(divCap * 0.5, bw * 0.5).C2D(W * 0.5, L * 0.5), ref ext, 50);
                        PLPloter.AddLine(db, pt.C2D(divCap * 0.5, bw * 0.5).C2D(W * 0.5, L * 0.5), pt.C2D(divCap * 0.5, bw * 0.5), ref ext, "H细线");
                        PLPloter.AddSolidCircle(db, pt.C2D(-divCap * 0.5, -bw * 0.5).C2D(-W * 0.5, -L * 0.5), ref ext, 50);
                        PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, -bw * 0.5).C2D(-W * 0.5, -L * 0.5), pt.C2D(-divCap * 0.5, -bw * 0.5), ref ext, "H细线");
                        PLPloter.AddSolidCircle(db, pt.C2D(divCap * 0.5, -bw * 0.5).C2D(W * 0.5, -L * 0.5), ref ext, 50);
                        PLPloter.AddLine(db, pt.C2D(divCap * 0.5, -bw * 0.5).C2D(W * 0.5, -L * 0.5), pt.C2D(divCap * 0.5, -bw * 0.5), ref ext, "H细线");

                        PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, bw * 0.5).C2D(-W * 0.5, L * 0.5), pt.C2D(divCap * 0.5, bw * 0.5).C2D(W * 0.5, L * 0.5), ref ext, "H细线");
                        PLPloter.AddLine(db, pt.C2D(divCap * 0.5, bw * 0.5).C2D(W * 0.5, L * 0.5), pt.C2D(divCap * 0.5, -bw * 0.5).C2D(W * 0.5, -L * 0.5), ref ext, "H细线");
                        PLPloter.AddLine(db, pt.C2D(divCap * 0.5, -bw * 0.5).C2D(W * 0.5, -L * 0.5), pt.C2D(-divCap * 0.5, -bw * 0.5).C2D(-W * 0.5, -L * 0.5), ref ext, "H细线");
                        PLPloter.AddLine(db, pt.C2D(-divCap * 0.5, -bw * 0.5).C2D(-W * 0.5, -L * 0.5), pt.C2D(-divCap * 0.5, bw * 0.5).C2D(-W * 0.5, L * 0.5), ref ext, "H细线");

                        DimPloter.DimAli(db, pt.C2D(-divCap * 0.5, bw * 0.5).C3D(-W * 0.5, L * 0.5), pt.C2D(-divCap * 0.5, -bw * 0.5).C3D(-W * 0.5, -L * 0.5), pt.C2D(-divCap * 0.5, 0).C3D(-W * 0.5-5*scale, -0), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter,1);
                        DimPloter.DimAli(db, pt.C2D(-divCap * 0.5, bw * 0.5).C3D(-W * 0.5, L * 0.5), pt.C2D(divCap * 0.5, bw * 0.5).C3D(W * 0.5, L * 0.5), pt.C2D(0, bw * 0.5).C3D(0, L * 0.5+ 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter, 2);
                    }
                    else
                    {
                        //扩基示意
                        Point2d pt = new Point2d(startStation + len, insertPoint.Y);
                        PLPloter.AddPloy4(db, pt.C2D(divCap * 0.2, bw * 0.8), divCap * 0.7, divCap * 0.7, bw * 1.6, ref ext, "H细线");
                        PLPloter.AddPloy4(db, pt.C2D(divCap * 0.6, bw * 0.25), divCap * 0.4, divCap * 0.4, bw * 0.5, ref ext, "H细线");
                        PLPloter.AddPloy4(db, pt.C2D(-divCap * 0.1, bw * 0.3), divCap * 0.2, divCap * 0.2, bw * 0.6, ref ext, "H细线");
                        PLPloter.AddPloy4(db, pt.C2D(divCap * 0.35, bw * 0.425), divCap * 0.65, divCap * 0.65, bw * 0.15, ref ext, "H细线");
                        PLPloter.AddPloy4(db, pt.C2D(divCap * 0.35, -bw * 0.3), divCap * 0.65, divCap * 0.65, bw * 0.15, ref ext, "H细线");
                    }
                    //}

                }
            }
            ptLst.Add(dPt1.C2D(bridgeLength));
            #region 添加标注
            DimPloter.DimAli(db, ptLst[0].C3D(), ptLst[ptLst.Count - 1].C3D(), ptLst[0].C2D(0, -15 * scale).C3D(), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            for (int i = 1; i < ptLst.Count; i++)
            {
                DimPloter.DimAli(db, ptLst[i - 1].C3D(), ptLst[i].C3D(), ptLst[0].C2D(0, -10 * scale).C3D(), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
            }

            #endregion


        }

        /// <summary>
        /// 表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public static void PlotTable(ref Database db, ref Extents2d ext, Point2d insertPoint)
        {
            Dictionary<string, List<double>> dic = new Dictionary<string, List<double>>();
            CalcauteLightInfo(ref dic);
            //ext = new Extents2d(insertPoint, insertPoint);
            DrawParaTable(db, ref ext, insertPoint.C3D(-light_distinct-scale * 0.85*2), dic, Extensions.curFont, scale * 0.85);
        }
        public static void DrawParaTable(Database db, ref Extents2d ext, Point3d startPoint, Dictionary<string, List<double>> dic, string txtStyle, double scale)
        {
            List<string> lst = dic.Keys.ToList();
            int rowNum = dic.Count + 1;
            List<double> lstLC = dic[lst[0]];
            int colNum = lstLC.Count + 1;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];

                // 创建table 
                Table tb = new Table();
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();

                #region 表格添加数据
                int index = 0;
                for (int i = 0; i < colNum; ++i)
                {

                    if (i == 0)
                    {

                        tb.Cells[0, 0].TextString = lst[0]; //获取i行j列数据
                        tb.Cells[0, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[0, 0].Contents[0].Rotation = 0;
                        tb.Cells[0, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[0, 0].Contents[0].TextStyleId = id;

                        tb.Cells[1, 0].TextString = lst[1]; //获取i行j列数据
                        tb.Cells[1, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[1, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, 0].Contents[0].Rotation = 0;
                        tb.Cells[1, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[1, 0].Contents[0].TextStyleId = id;

                        tb.Cells[2, 0].TextString = lst[2]; //获取i行j列数据
                        tb.Cells[2, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[2, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2, 0].Contents[0].Rotation = 0;
                        tb.Cells[2, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[2, 0].Contents[0].TextStyleId = id;

                        tb.Cells[3, 0].TextString = lst[3]; //获取i行j列数据
                        tb.Cells[3, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[3, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[3, 0].Contents[0].Rotation = 0;
                        tb.Cells[3, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[3, 0].Contents[0].TextStyleId = id;

                        tb.Cells[4, 0].TextString = lst[4]; //获取i行j列数据
                        tb.Cells[4, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[4, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[4, 0].Contents[0].Rotation = 0;
                        tb.Cells[4, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[4, 0].Contents[0].TextStyleId = id;

                        tb.Cells[5, 0].TextString = "坡度/坡长"; //获取i行j列数据
                        tb.Cells[5, 0].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[5, 0].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[5, 0].Contents[0].Rotation = 0;
                        tb.Cells[5, 0].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[5, 0].Contents[0].TextStyleId = id;
                    }
                    else
                    {
                        tb.Cells[0, i].TextString = (dic[lst[0]][i - 1]).ToString(); //获取i行j列数据                      
                        tb.Cells[0, i].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[0, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[0, i].Contents[0].Rotation = 0;
                        tb.Cells[0, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[0, i].Contents[0].TextStyleId = id;

                        tb.Cells[1, i].TextString = (dic[lst[1]][i - 1]).ToString(); //获取i行j列数据
                        tb.Cells[1, i].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[1, i].Contents[0].Rotation = 0;
                        tb.Cells[1, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[1, i].Contents[0].TextStyleId = id;

                        tb.Cells[2, i].TextString = dic[lst[2]][i - 1].ToString("0.000"); //获取i行j列数据
                        tb.Cells[2, i].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[2, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[2, i].Contents[0].Rotation = 0;
                        tb.Cells[2, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[2, i].Contents[0].TextStyleId = id;

                        tb.Cells[3, i].TextString = dic[lst[3]][i - 1].ToString("0.000"); //获取i行j列数据
                        tb.Cells[3, i].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[3, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[3, i].Contents[0].Rotation = 0;
                        tb.Cells[3, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[3, i].Contents[0].TextStyleId = id;

                        tb.Cells[4, i].TextString = dic[lst[4]][i - 1].ToString("0.000"); //获取i行j列数据
                        tb.Cells[4, i].Contents[0].TextHeight = 3 * scale;
                        tb.Cells[4, i].Alignment = CellAlignment.MiddleCenter;
                        tb.Cells[4, i].Contents[0].Rotation = 0;
                        tb.Cells[4, i].Borders.Horizontal.Margin = 2 * scale;
                        tb.Cells[4, i].Contents[0].TextStyleId = id;
                    }

                }
                #endregion
                tb.MergeCells(CellRange.Create(tb, 5, 1, 5, colNum - 1));
                // 设置列宽,行高
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = light_distinct+2*scale;
                    else
                        tb.Columns[i].Width = light_distinct;

                }

                for (int i = 0; i < rowNum; ++i)
                {
                    if (i == rowNum -3)
                        tb.Rows[i].Height = 12 * scale;
                    else if (i < rowNum - 1)
                        tb.Rows[i].Height = 8 * scale;
                    else
                        tb.Rows[i].Height = 10 * scale;
                }
                if (bridgeSlope > 0)
                {
                    PLPloter.AddLine(db, startPoint.C2D(light_distinct, -8 * scale * 5-4*scale), startPoint.C2D(tb.Width, -8 * scale * 5 - 4 * scale - 10 * scale), ref ext, "H细线");
                    Point3d ptTxt = GeTools.MidPoint(startPoint.C3D(light_distinct, -8 * scale * 5 - 4 * scale), startPoint.C3D(tb.Width, -8 * scale * 5 - 4 * scale - 10 * scale));
                    double rod = Math.Atan(10 * scale / bridgeLength);
                    TextPloter.AddDBText(db, ptTxt, ref ext, (bridgeSlope * 100).ToString() + "%", scale, 2.5, Extensions.curFont, rod);
                    TextPloter.AddDBText(db, ptTxt.C3D(0, -4 * scale), ref ext, (bridgeLength / 100).ToString(), scale, 2.5, Extensions.curFont, rod);
                }
                else
                {

                    PLPloter.AddLine(db, startPoint.C2D(light_distinct, -8 * scale * 5 - 4 * scale - 10 * scale), startPoint.C2D(tb.Width, -8 * scale * 5 - 4 * scale), ref ext, "H细线");
                    Point3d ptTxt = GeTools.MidPoint(startPoint.C3D(light_distinct, -8 * scale * 5 - 4 * scale - 10 * scale), startPoint.C3D(tb.Width, -8 * scale * 5 - 4 * scale));
                    double rod = Math.Atan(-10 * scale / bridgeLength);
                    TextPloter.AddDBText(db, ptTxt, ref ext, (bridgeSlope * 100).ToString() + "%", scale, 2.5, Extensions.curFont, rod);
                    TextPloter.AddDBText(db, ptTxt.C3D(0, -4 * scale), ref ext, (bridgeLength / 100).ToString(), scale, 2.5, Extensions.curFont, rod);

                }
                tb.LayerId = lt["H细线"];
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.C2D(), tb.Bounds.Value.MaxPoint.C2D()));

                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.C2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.C2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.C2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.C2D(tb.Width, 0);
                pList.Add(pt4);
                PLPloter.AddPolylineByPointList(db, pList, ref ext, "H粗线", true);

                tr.Commit();


            }
        }

        private static void CalcauteLightInfo(ref Dictionary<string, List<double>> dic)
        {

            Point2d dPt1 = Point2d.Origin;
            double designHeight = 0;
            double designReferHeight = 0;
            double divCap = 0, divHeight = 0;
            double startStation = 0;
            double bridgeLength = 0;
            double light_start_station = 0;

            Line lineD = new Line();
            //Point2d dPt2 = Point2d.Origin;
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
                startStation = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station"].ToString()) * 100;
                double bridgeSlope = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_slope"].ToString());
                bridgeLength = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_length"].ToString()) * 100;
                designHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["start_station_design_height"].ToString()) * 100;
                divCap = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_section_width"].ToString()) * 100;
                divHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_height"].ToString()) * 100;
                light_start_station = double.Parse(dtAviationBridgeInfo.Rows[0]["light_start_station"].ToString()) * 100;
                light_distinct = double.Parse(dtAviationBridgeInfo.Rows[0]["light_distinct"].ToString()) * 100;
                designReferHeight = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["start_station_refer_design_height"].ToString()) ? designHeight : double.Parse(dtAviationBridgeInfo.Rows[0]["start_station_refer_design_height"].ToString())*100;
                double startL = light_start_station - startStation;
                //if (startL % divCap != 0)
                //    light_start_station = (startStation + ((int)(startL / divCap)) * divCap) == startStation ? startStation + divCap * 2 : (startStation + ((int)(startL / divCap)) * divCap);

                int num = (int)(bridgeLength / divCap);
                num = (bridgeLength - divCap * num) > 0 ? num + 1 : num;
                //bridgeLength = num * divCap;

                dPt1 = new Point2d(startStation, designHeight);

                Point2d dPt2 = dPt1;
                if (isStartLeft)
                {
                    dPt2 = dPt1.C2D(bridgeLength, -bridgeLength * bridgeSlope*0.01);

                }
                else
                {
                    dPt2 = dPt1.C2D(-bridgeLength, -bridgeLength * bridgeSlope * 0.01);
                }


                Point2d dpt1 = dPt1;
                Point2d dpt2 = dPt1.C2D(divCap, -divCap * bridgeSlope);

                lineD = new Line(dPt1.C3D(), dPt2.C3D());


            }
            double dx = 0, dy = 0;
            double xDesign = startStation;
            //int index0 = dxfPointLst.FindIndex(o => o.X >= xDesign) > 0 ? dxfPointLst.FindIndex(o => o.X > xDesign) : dxfPointLst.Count - 2;
            //int index01 = dxfPointLst.FindLastIndex(o => o.X < xDesign) > 0 ? dxfPointLst.FindLastIndex(o => o.X < xDesign) : 0;
            //Line line20 = new Line(new Point3d(xDesign, 0, 0), new Point3d(xDesign, 1, 0));
            //Point3d ptDG = MathExtensions.GetIntersection(lineD, line20);
            dy = designHeight * 0.01 - designReferHeight * 0.01;
            dx = startStation - refStartSt;
            //dy = ptDG.Y * 0.01 - designReferHeight*0.01;

            double len = light_start_station;
            int numL = (int)((bridgeLength - (light_start_station - startStation)) / light_distinct);
            List<double> lcLst = new List<double>();
            List<double> noLst = new List<double>();
            List<double> dmLst = new List<double>();
            List<double> sjLst = new List<double>();
            List<double> dxLst = new List<double>();
         
            for (int i = 0; i <= numL; i++)
            {
             
                len = light_distinct * i;
                double x = light_start_station + len;
          
                int index = dxfPointLst.FindIndex(o => o.X >= x) > 0 ? dxfPointLst.FindIndex(o => o.X > x) : dxfPointLst.Count - 2;
                int index1 = dxfPointLst.FindLastIndex(o => o.X < x) > 0 ? dxfPointLst.FindLastIndex(o => o.X < x ) : 0;
                Line line1 = new Line(dxfPointLst[index1].C3D(), dxfPointLst[index].C3D());
                if (index1 == 0)
                    line1 = new Line(dxfPointLst[0].C3D(), dxfPointLst[1].C3D());
               
                Line line2 = new Line(new Point3d(x, 0, 0), new Point3d(x, 1, 0));
                Point3d ptD = MathExtensions.GetIntersection(line1, line2);
                Point3d ptG = MathExtensions.GetIntersection(lineD, line2);
                //if(i==0)
                //{
                //    dx = x;
                //}
                lcLst.Add((x - dx)*0.01);
                noLst.Add(startLightNo);
                dmLst.Add(ptD.Y * 0.01-dy);
                sjLst.Add(ptG.Y * 0.01 - dy);
                dxLst.Add(ptG.Y * 0.01 + lightHeight - dy);
                startLightNo++;
            }
            if (bridgeLength - (light_start_station - startStation) < numL * light_distinct)
            {
                double x = startStation + bridgeLength;
              
                int index = dxfPointLst.FindIndex(o => o.X >= x ) > 0 ? dxfPointLst.FindIndex(o => o.X < x) : dxfPointLst.Count - 2;
                int index1 = dxfPointLst.FindLastIndex(o => o.X < x ) > 0 ? dxfPointLst.FindLastIndex(o => o.X < x) : 0;
                Line line1 = new Line(dxfPointLst[index1].C3D(), dxfPointLst[index].C3D());
                if (index1 == 0)
                    line1 = new Line(dxfPointLst[0].C3D(), dxfPointLst[1].C3D());

                Line line2 = new Line(new Point3d(x, 0, 0), new Point3d(x, 1, 0));
                Point3d ptD = MathExtensions.GetIntersection(line1, line2);
                Point3d ptG = MathExtensions.GetIntersection(lineD, line2);
                lcLst.Add((x - dx) * 0.01);
                noLst.Add(startLightNo);
                dmLst.Add(ptD.Y * 0.01 - dy);
                sjLst.Add(ptG.Y * 0.01 - dy);
                dxLst.Add(ptG.Y * 0.01 + lightHeight - dy);
            }
            dic.Add("距跑道入口", lcLst);
            dic.Add("进近灯编号", noLst);
            dic.Add("灯芯高程", dxLst);
            dic.Add("桥面弦杆\\P中心线高程", sjLst);
            dic.Add("地面高程", dmLst);

        }
        /// <summary>
        /// 其他信息
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="scale"></param>
        public static void PlotDetail(ref Database db, out Extents2d ext, Point2d insertPoint, double scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            try
            {
                //string path = Extensions.curAppPath + "Aviation.dwg";
                //string _blcName = "aviationSection" + bridgeW;
                //if(bridgeW==450)
                //    _blcName = "DLDJ";
                //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H细线", insertPoint.C3D(0, 5*100), ref ext, 1, 0, true, false);

                string text = @"注: 1.本图尺寸除标高与里程以米计外，其余均以厘米为单位";
                Point3d p = insertPoint.C3D(0, -300);

                TextPloter.AddMText(db, p, ref ext, text, scale, 2.5, 100 * scale, Extensions.curFont);

            }
            catch
            {

            }

        }


        public static void PlotDetailNew(ref Database db, out Extents2d ext, Point2d insertPoint,double scale=100)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            try
            {
                double W = 0;
                double H = 0;
                Point2d sectPoint = insertPoint;
                Extents2d extS = new Extents2d(sectPoint, sectPoint);
                TextPloter.AddTitle(db, sectPoint.C2D(0, 5 * scale), ref extS, "墩顶断面", "", scale);
                AddSection(ref db, ref extS, sectPoint, scale, true,false);
                ext = ext.Add(extS);
                W = extS.W();
                H = extS.L();

                sectPoint = insertPoint.C2D(W * 1.2 + 20 * scale);
                extS = new Extents2d(sectPoint, sectPoint);
                TextPloter.AddTitle(db, sectPoint.C2D(0, 5 * scale), ref extS, "灯具断面(墩顶区)", "", scale);
                AddSection(ref db, ref extS, sectPoint, scale, true, true);
                ext = ext.Add(extS);

                H = extS.L() > H ? extS.L() : H;               
                sectPoint = insertPoint.C2D(0, -(H + 10 * scale));
                extS = new Extents2d(sectPoint, sectPoint);
                TextPloter.AddTitle(db, sectPoint.C2D(0, 5 * scale), ref extS, "中跨/悬臂端断面", "", scale);
                AddSection(ref db, ref extS, sectPoint, scale, false,false);
                ext = ext.Add(extS);

                sectPoint = insertPoint.C2D(W * 1.2 + 20 * scale, -(H + 10 * scale));
                extS = new Extents2d(sectPoint, sectPoint);
                TextPloter.AddTitle(db, sectPoint.C2D(0, 5 * scale), ref extS, "灯具断面(中跨/悬臂端区)", "", scale);
                AddSection(ref db, ref extS, sectPoint, scale, false, true);
                ext = ext.Add(extS);

                //string path = Extensions.curAppPath + "Aviation.dwg";
                //string _blcName = "aviationSection" + bridgeW;
                //if (bridgeW == 450)
                //    _blcName = "DLDJ";
                //BlockPlot.InsertBlockByDwg(db, path, _blcName, "H细线", insertPoint.C3D(0, 5 * 100), ref ext, 1, 0, true, false);

                string text = @"注:
 1.本图尺寸除标高与里程以米计外，其余均以厘米为单位";
                Point3d p = insertPoint.C3D(0, -ext.L() - 3 * scale);

                 TextPloter.AddMText(db, p, ref ext, text, scale, 2.5, 100 * scale, Extensions.curFont);

            }
            catch
            {

            }

        }

        /// <summary>
        /// 绘制断面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="insertPoint"></param>
        /// <param name="isReinforced">是否加强断面</param>
        /// <param name="isAddLight">是否灯具断面</param>
        public static void AddSection(ref Database db, ref Extents2d ext, Point2d insertPoint,double scale,bool isReinforced=false, bool isAddLight=false)
        {
            double divCap = 0, lightHeight = 0, divHeight = 0;
            double netCap = 60;
            double btCap = 100;
            double lightCap = 250;
            double guardrail_height = 1500;
            if (dtAviationBridgeInfo.Rows.Count > 0)
            {
                double lightH = string.IsNullOrWhiteSpace(dtAviationBridgeInfo.Rows[0]["light_height"].ToString()) ? 2.04 : double.Parse(dtAviationBridgeInfo.Rows[0]["light_height"].ToString());
                divCap = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_section_width"].ToString()) * 1000;
                divHeight = double.Parse(dtAviationBridgeInfo.Rows[0]["beam_height"].ToString()) * 1000;
                DataRow dr = dtSection.Rows[0];
                string straight_web_bar = dr["straight_web_bar"].ToString().Contains("HN") || dr["straight_web_bar"].ToString().Contains("HW") || dr["straight_web_bar"].ToString().Contains("HM") ? dr["straight_web_bar"].ToString() : "矩形管" + dr["straight_web_bar"].ToString();
                string reinforced_straight_web_bar = dr["reinforced_straight_web_bar"].ToString().Contains("HN") || dr["reinforced_straight_web_bar"].ToString().Contains("HW") || dr["reinforced_straight_web_bar"].ToString().Contains("HM") ? dr["reinforced_straight_web_bar"].ToString() : "矩形管" + dr["reinforced_straight_web_bar"].ToString();
                string diagonal_brace = dr["diagonal_brace"].ToString().Contains("HN") || dr["diagonal_brace"].ToString().Contains("HW") || dr["diagonal_brace"].ToString().Contains("HM") ? dr["diagonal_brace"].ToString() : "矩形管" + dr["diagonal_brace"].ToString();
                string reinforced_diagonal_brace = dr["reinforced_diagonal_brace"].ToString().Contains("HN") || dr["reinforced_diagonal_brace"].ToString().Contains("HW") || dr["reinforced_diagonal_brace"].ToString().Contains("HM") ? dr["reinforced_diagonal_brace"].ToString() : "矩形管" + dr["reinforced_diagonal_brace"].ToString();
                string web_bar = dr["web_bar"].ToString().Contains("HN") || dr["web_bar"].ToString().Contains("HW") || dr["web_bar"].ToString().Contains("HM") ? dr["web_bar"].ToString() : "矩形管" + dr["web_bar"].ToString();
                string reinforced_web_bar = dr["reinforced_web_bar"].ToString().Contains("HN") || dr["reinforced_web_bar"].ToString().Contains("HW") || dr["reinforced_web_bar"].ToString().Contains("HM") ? dr["reinforced_web_bar"].ToString() : "矩形管" + dr["reinforced_web_bar"].ToString();
                lightHeight = lightH * 1000;
                Point2d pt = insertPoint.C2D(0, -lightHeight - 8 * scale);
                double bW = bridgeW * 10;
                PLPloter.AddPloy4(db, pt, bW * 0.5, bW * 0.5, divHeight, ref ext, "H细线");

                //杆件尺寸
                string[] sizeWebBar = reinforced_straight_web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//主管
                string[] sizeBrace = reinforced_diagonal_brace.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//斜腹杆
                string[] sizeWebMember = web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//腹杆
               
                if (isReinforced)
                {
                    //主管尺寸
                    sizeWebBar = reinforced_straight_web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//主管
                    sizeBrace = reinforced_diagonal_brace.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//斜腹杆
                    sizeWebMember = reinforced_web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//腹杆
                }
                else
                {
                    //主管尺寸
                    sizeWebBar = straight_web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//主管
                    sizeBrace = diagonal_brace.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//斜腹杆
                    sizeWebMember = web_bar.Replace("矩形管", "").Replace("HN", "").Replace("HW", "").Split('*');//腹杆
                }
                double w = double.Parse(sizeWebBar[1]);
                double h = double.Parse(sizeWebBar[0]);


                #region 主管绘制
                PLPloter.AddPloy4(db, pt.C2D(-bW * 0.5, h * 0.5), w * 0.5, w * 0.5, h, ref ext, "H粗线");
                PLPloter.AddPloy4(db, pt.C2D(bW * 0.5, h * 0.5), w * 0.5, w * 0.5, h, ref ext, "H粗线");
                PLPloter.AddPloy4(db, pt.C2D(-bW * 0.5, -divHeight + h * 0.5), w * 0.5, w * 0.5, h, ref ext, "H粗线");
                PLPloter.AddPloy4(db, pt.C2D(bW * 0.5, -divHeight + h * 0.5), w * 0.5, w * 0.5, h, ref ext, "H粗线");
                DimPloter.DimAli(db, pt.C3D(-bW * 0.5 - w * 0.5, -divHeight + h * 0.5), pt.C3D(-bW * 0.5 + w * 0.5, -divHeight + h * 0.5), pt.C3D(0, -divHeight - h * 0.5 - 3 * scale), ref ext, scale, (w * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimAli(db, pt.C3D(-bW * 0.5 - w * 0.5, -divHeight + h * 0.5), pt.C3D(-bW * 0.5 - w * 0.5, -divHeight - h * 0.5), pt.C3D(-bW * 0.5 - w * 0.5 - 5 * scale, -divHeight), ref ext, scale, (h * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
               
                #endregion

                #region 上下弦杆绘制
                double h1 = double.Parse(sizeBrace[0]);
                double w1 = bW - w;
                double w2 = divHeight - h;
                //上下弦杆绘制
                if (isAddLight)
                {
                    if (bW < 4500)
                    {
                        PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5), w1 * 0.5, w1 * 0.5, h1, ref ext, "H粗线");
                        PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5), 4650 * 0.5, 4650 * 0.5, h1, ref ext, "H粗线");
                        if (bW < 4000)
                        {
                            double ww = 400;
                            PLPloter.AddLine(db, pt.C2D(-w * 0.5 - bW * 0.5, h1 * 0.5 - h1 - ww), pt.C2D(-w * 0.5 - bW * 0.5 - ww, h1 * 0.5 - h1), ref ext, "H细线");
                            PLPloter.AddLine(db, pt.C2D(-w * 0.5 - bW * 0.5, h1 * 0.5 - h1 - ww + 100), pt.C2D(-w * 0.5 - bW * 0.5 - ww + 100, h1 * 0.5 - h1), ref ext, "H细线");

                            PLPloter.AddLine(db, pt.C2D(w * 0.5 + bW * 0.5, h1 * 0.5 - h1 - ww), pt.C2D(w * 0.5 + bW * 0.5 + ww, h1 * 0.5 - h1), ref ext, "H细线");
                            PLPloter.AddLine(db, pt.C2D(w * 0.5 + bW * 0.5, h1 * 0.5 - h1 - ww + 100), pt.C2D(w * 0.5 + bW * 0.5 + ww - 100, h1 * 0.5 - h1), ref ext, "H细线");
                        }
                    }
                    else
                    {
                        PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5), w1 * 0.5, w1 * 0.5, h1, ref ext, "H粗线");
                    }
                }
                else
                {
                    PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5), w1 * 0.5, w1 * 0.5, h1, ref ext, "H粗线");
                }
                //PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5), w1 * 0.5-0.1, w1 * 0.5 - 0.1, h1 - 0.2, ref ext, "H虚线");
                PLPloter.AddPloy4(db, pt.C2D(0, -divHeight + h1 * 0.5), w1 * 0.5, w1 * 0.5, h1, ref ext, "H粗线");
                DimPloter.DimAli(db, pt.C3D(bW * 0.25, -divHeight + h1 * 0.5), pt.C3D(bW * 0.25, -divHeight - h1 * 0.5), pt.C3D(bW * 0.25, -divHeight), ref ext, scale, (h1 * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                #endregion

                #region 竖杆
                PLPloter.AddPloy4(db, pt.C2D(bW * 0.5, -h * 0.5), h1 * 0.5, h1 * 0.5, w2, ref ext, "H粗线");
                PLPloter.AddPloy4(db, pt.C2D(-bW * 0.5, -h * 0.5), h1 * 0.5, h1 * 0.5, w2, ref ext, "H粗线");
              

                DimPloter.DimAli(db, pt.C3D(-bW * 0.5 - h1 * 0.5, -divHeight * 0.5), pt.C3D(-bW * 0.5 + h1 * 0.5, -divHeight * 0.5), pt.C3D(0, -divHeight * 0.5), ref ext, scale, (h1 * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);

                if (isReinforced)
                {
                    DimPloter.AddMultiMLeader(db, pt.C2D(-bW * 0.5, -divHeight*0.25), pt.C2D(-bW * 0.5  + 2 * scale, -divHeight * 0.25 + 2 * scale), pt.C2D(-bW * 0.5 + 2 * scale, -divHeight * 0.25 + 2 * scale), reinforced_web_bar, ref ext, scale);
                }
                else
                {
                    DimPloter.AddMultiMLeader(db, pt.C2D(-bW * 0.5, -divHeight * 0.25), pt.C2D(-bW * 0.5 + 2 * scale, -divHeight * 0.25 + 2 * scale), pt.C2D(-bW * 0.5 + 2 * scale, -divHeight * 0.25 + 2 * scale), web_bar, ref ext, scale);
                }
                #endregion

                #region 斜腹杆
                double ang = Math.Atan((divHeight) / (bridgeW * 10 * 0.5 - w * 0.5 - btCap));
                //double wMid = double.Parse(sizeWebMember[1]);
                double hMid = double.Parse(sizeWebMember[0])*0.5;
                double wMid = hMid / Math.Sin(ang);
                double midw = h1*0.5 / Math.Tan(ang);
                Point2d pt1 = pt.C2D(-midw,-h1*0.5);
                Point2d pt2 = pt.C2D(-bW * 0.5+w*0.5+ btCap+ midw, -divHeight+ h1 * 0.5);

                Point2d pt3 = pt.C2D(midw, -h1 * 0.5);
                Point2d pt4 = pt.C2D(bW * 0.5 - w * 0.5 - btCap - midw, -divHeight + h1 * 0.5);

                //计算交点
                Line line1 = new Line(pt1.C3D(wMid), pt2.C3D(wMid));
                Line line2 = new Line(pt3.C3D(-wMid), pt4.C3D(-wMid));
                Point3d ptIn = MathExtensions.GetIntersection(line1, line2);

                PLPloter.AddScaleLine(db, pt1.C2D(), pt2.C2D(), ref ext, "H中心线", 3);            
                PLPloter.AddLine(db, pt1.C2D(-wMid), pt2.C2D(-wMid), ref ext, "H细线");
                PLPloter.AddLine(db, pt1.C2D(wMid), pt2.C2D(wMid), ref ext, "H细线");

                
                PLPloter.AddScaleLine(db, pt3.C2D(), pt4.C2D(), ref ext, "H中心线", 3);
                PLPloter.AddLine(db, ptIn.C2D(), pt4.C2D(-wMid), ref ext, "H细线");
                PLPloter.AddLine(db, pt3.C2D(wMid), pt4.C2D(wMid), ref ext, "H细线");

                DimPloter.DimAli(db, pt.C3D(-bW * 0.5, -divHeight * 0.5), pt.C3D(-bW * 0.5 + w * 0.5+btCap, -divHeight * 0.5), pt.C3D(0, -divHeight * 0.75), ref ext, scale, ((w*0.5+ btCap)* 0.1).ToString(), Unit.Centimeter, Unit.Centimeter,0);
                double dis = MathExtensions.PointDistance(pt1,pt2);

              
                    #endregion

                    #region  钢隔珊
                    if (isAddLight)
                {
                    bW = 4500;
                }
                else
                {
                    bW = bridgeW * 10;
                }
                double hnet =50+5;// h*0.5 - h1*0.5-5;
                if (bridgeW * 10 < 4500)
                {
                    if (!isAddLight)
                        PLPloter.AddPloy4WithHatch(db, pt.C2D(0, h1 * 0.5 + hnet), (bW - w) * 0.5 - netCap, (bW - w) * 0.5 - netCap, hnet-5, ref ext, "H细线", "ANGLE",scale);
                    else
                        PLPloter.AddPloy4WithHatch(db, pt.C2D(0, h1 * 0.5 + hnet), (bW-60) * 0.5 - netCap, (bW - 60) * 0.5 - netCap, hnet - 5, ref ext, "H细线", "ANGLE", scale);

                   
                }
                else
                    PLPloter.AddPloy4WithHatch(db, pt.C2D(0, h1 * 0.5 + hnet), (bW - w) * 0.5 - netCap, (bW - w) * 0.5 - netCap, hnet - 5, ref ext, "H细线", "ANGLE", scale);

                PLPloter.AddLine(db, pt.C2D(-((bW - w) * 0.5 - netCap), h1 * 0.5 + hnet + 10), pt.C2D(-((bW - w) * 0.5 - netCap), h1 * 0.5), ref ext, "H粗线");
                PLPloter.AddLine(db, pt.C2D(((bW - w) * 0.5 - netCap), h1 * 0.5 + hnet + 10), pt.C2D(((bW - w) * 0.5 - netCap), h1 * 0.5), ref ext, "H粗线");
                #endregion


                #region 护栏

                if (isAddLight)
                {
                    if (bridgeW * 10 < 4500)
                    {
                        PLPloter.AddPoly8(db, pt.C2D(bW * 0.5, h * 0.5 + 200), ref ext, 200+ h * 0.5-h1*0.5, 120, "H粗线", 20, 30, 0, 0);
                        PLPloter.AddPoly8(db, pt.C2D(-bW * 0.5, h * 0.5 + 200), ref ext, 200 + h * 0.5 - h1 * 0.5, 120, "H粗线", 20, 30, 0, 0);
                    }
                    else
                    {
                        PLPloter.AddPoly8(db, pt.C2D(bW * 0.5, h * 0.5 + 200), ref ext, 200, 120, "H粗线", 20, 30, 0, 0);
                        PLPloter.AddPoly8(db, pt.C2D(-bW * 0.5, h * 0.5 + 200), ref ext, 200, 120, "H粗线", 20, 30, 0, 0);
                    }
                }
                else
                {
                    PLPloter.AddPoly8(db, pt.C2D(bW * 0.5, h * 0.5 + 200), ref ext, 200, 120, "H粗线", 20, 30, 0, 0);
                    PLPloter.AddPoly8(db, pt.C2D(-bW * 0.5, h * 0.5 + 200), ref ext, 200, 120, "H粗线", 20, 30, 0, 0);
                }
              
                PLPloter.AddLine(db, pt.C2D(bW * 0.5 - 60, h * 0.5 + 120), pt.C2D(bW * 0.5 + 60, h * 0.5 + 120), ref ext, "H细线");
                PLPloter.AddLine(db, pt.C2D(bW * 0.5 - 60, h * 0.5 + 60), pt.C2D(bW * 0.5 + 60, h * 0.5 + 60), ref ext, "H细线");

                PLPloter.AddLine(db, pt.C2D(-bW * 0.5 - 60, h * 0.5 + 120), pt.C2D(-bW * 0.5 + 60, h * 0.5 + 120), ref ext, "H细线");
                PLPloter.AddLine(db, pt.C2D(-bW * 0.5 - 60, h * 0.5 + 60), pt.C2D(-bW * 0.5 + 60, h * 0.5 + 60), ref ext, "H细线");
                for (int i = 0; i < 4; i++)
                {
                    if (i < 3)
                    {
                        PLPloter.AddCircle(db, pt.C2D(-bW * 0.5, h * 0.5 + 300 + 400 * i), 40, ref ext, "H细线");
                        PLPloter.AddCircle(db, pt.C2D(bW * 0.5, h * 0.5 + 300 + 400 * i), 40, ref ext, "H细线");
                    }
                    else
                    {
                        PLPloter.AddCircle(db, pt.C2D(-bW * 0.5, h * 0.5 + 300 + 400 * i - 40), 40, ref ext, "H细线");
                        PLPloter.AddCircle(db, pt.C2D(bW * 0.5, h * 0.5 + 300 + 400 * i - 40), 40, ref ext, "H细线");
                    }
                }

                PLPloter.AddPloy4(db, pt.C2D(bW * 0.5, h * 0.5 + guardrail_height), (120 - 20 * 2) * 0.5, (120 - 20 * 2) * 0.5, guardrail_height - 200, ref ext, "H粗线");
                PLPloter.AddPloy4(db, pt.C2D(-bW * 0.5, h * 0.5 + guardrail_height), (120 - 20 * 2) * 0.5, (120 - 20 * 2) * 0.5, guardrail_height - 200, ref ext, "H粗线");

                if (isAddLight)
                {
                    if (bridgeW * 10 < 4500)
                    {
                        PLPloter.AddScaleLine(db, pt.C2D(-bW * 0.5, h1 * 0.5), pt.C2D(-bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                        PLPloter.AddScaleLine(db, pt.C2D(bW * 0.5, h1 * 0.5), pt.C2D(bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                    }
                    else
                    {
                        PLPloter.AddScaleLine(db, pt.C2D(-bW * 0.5, h * 0.5), pt.C2D(-bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                        PLPloter.AddScaleLine(db, pt.C2D(bW * 0.5, h * 0.5), pt.C2D(bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                    }
                }
                else
                {
                    PLPloter.AddScaleLine(db, pt.C2D(-bW * 0.5, h * 0.5), pt.C2D(-bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(bW * 0.5, h * 0.5), pt.C2D(bW * 0.5, h * 0.5 + guardrail_height), ref ext, "H中心线", 3);
                }

                #endregion

                #region 灯
                if (isAddLight)
                {
                    double hlight =220;
                    double hBlight = 20;
                    PLPloter.AddPloy4(db, pt.C2D(-120, h1 * 0.5 + lightHeight - hlight), (50) * 0.5, (50) * 0.5, lightHeight - hlight- hnet- hBlight, ref ext, "H细线");
                    PLPloter.AddPloy4(db, pt.C2D(120, h1 * 0.5 + lightHeight - hlight), (50) * 0.5, (50) * 0.5, lightHeight - hlight- hnet- hBlight, ref ext, "H细线");
                    PLPloter.AddPloy4(db, pt.C2D(0, h1 * 0.5 + lightHeight - hlight + hnet), (bW - 150) * 0.5, (bW - 150) * 0.5, hnet-5, ref ext, "H细线");

                    PLPloter.AddScaleLine(db, pt.C2D(-120, h1 * 0.5 + hnet + hBlight), pt.C2D(-120, h1 * 0.5 + lightHeight - hlight), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(120, h1 * 0.5 + hnet + hBlight), pt.C2D(120, h1 * 0.5 + lightHeight - hlight), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(-(bW - 150) * 0.5, h1 * 0.5 + lightHeight - hlight + hnet*0.5), pt.C2D((bW - 150) * 0.5, h1 * 0.5 + lightHeight - hlight + hnet * 0.5), ref ext, "H中心线", 3);

                    PLPloter.AddScaleLine(db, pt.C2D(0, h1 * 0.5 + hnet + hBlight), pt.C2D(0, h1 * 0.5 + lightHeight - hlight), ref ext, "H中心线", 3);

                    PLPloter.AddScaleLine(db, pt.C2D(-120, h1 * 0.5 + hnet + hBlight), pt.C2D(120, h1 * 0.5 + (lightHeight - hlight) * 0.5), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(120, h1 * 0.5 + hnet + hBlight), pt.C2D(-120, h1 * 0.5 + (lightHeight - hlight) * 0.5), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(-120, h1 * 0.5 + (lightHeight - hlight) * 0.5), pt.C2D(120, h1 * 0.5 + lightHeight - hlight), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(120, h1 * 0.5 + (lightHeight - hlight) * 0.5), pt.C2D(-120, h1 * 0.5 + lightHeight - hlight), ref ext, "H中心线", 3);
                    PLPloter.AddScaleLine(db, pt.C2D(-120, h1 * 0.5 + (lightHeight - hlight) * 0.5), pt.C2D(120, h1 * 0.5 + (lightHeight - hlight) * 0.5), ref ext, "H中心线", 3);
                    //if(h*0.5-h1*0.5>hnet)
                    //{
                    //    PLPloter.AddPloy4WithHatch(db, pt.C2D(0, h1 * 0.5 +  h * 0.5 - h1 * 0.5), 200, 200, h * 0.5 - h1 * 0.5, ref ext, "H粗线", "NET");
                    //}
                    PLPloter.AddPloy4WithHatch(db, pt.C2D(0, h1 * 0.5 + hnet+ hBlight), 200, 200, hBlight, ref ext, "H细线", "NET",scale);
                    DimPloter.DimAli(db, pt.C3D(0, 0), pt.C3D(0, h1 * 0.5 + lightHeight), pt.C3D(120 + 5 * scale, 0), ref ext, scale, (lightHeight * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                    for (int i = 0; i < 5; i++)
                    {
                        PLPloter.AddPloy4(db, pt.C2D(-2000 + 1000 * i, h1 * 0.5 + lightHeight), (20) * 0.5, (20) * 0.5, hlight - 10, ref ext, "H细线");
                        PLPloter.AddCircle(db, pt.C2D(-2000 + 1000 * i, h1 * 0.5 + lightHeight), 40, ref ext, "H细线");
                        if (i == 1)
                        {
                            PLPloter.AddPloy4(db, pt.C2D(-2000 + 1000 * i + 500, h1 * 0.5 + lightHeight), (20) * 0.5, (20) * 0.5, hlight - 10, ref ext, "H细线");
                            PLPloter.AddCircle(db, pt.C2D(-2000 + 1000 * i + 500, h1 * 0.5 + lightHeight), 40, ref ext, "H细线");
                        }
                    }

                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5), insertPoint.C3D(-bW * 0.5 + lightCap), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, (lightCap * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5 + lightCap), insertPoint.C3D(bW * 0.5 - lightCap), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, (bW * 0.1 - lightCap * 0.1 * 2).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(bW * 0.5 - lightCap), insertPoint.C3D(bW * 0.5), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, (lightCap * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5), insertPoint.C3D(bW * 0.5), pt.C3D(0, lightHeight + 9 * scale), ref ext, scale, (bW * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                }
                else
                {
                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5), insertPoint.C3D(-bW * 0.5 + netCap + w * 0.5), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, ((netCap + w * 0.5) * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5 + netCap + w * 0.5), insertPoint.C3D(bW * 0.5 - netCap - w * 0.5), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, (bW * 0.1 - (netCap + w * 0.5) * 0.1 * 2).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(bW * 0.5 - netCap - w * 0.5), insertPoint.C3D(bW * 0.5), pt.C3D(0, lightHeight + 5 * scale), ref ext, scale, ((netCap + w * 0.5) * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                    DimPloter.DimAli(db, insertPoint.C3D(-bW * 0.5), insertPoint.C3D(bW * 0.5), pt.C3D(0, lightHeight + 9 * scale), ref ext, scale, (bW * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                }
                #endregion

                #region 标注
                DimPloter.DimAli(db, pt.C3D(bW * 0.5 + w * 0.5, 0), pt.C3D(bW * 0.5 + w * 0.5, -divHeight), pt.C3D(bW * 0.5 + w * 0.5 + 5 * scale), ref ext, scale, (divHeight * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimAli(db, pt.C3D(bW * 0.5 + w * 0.5, 0), pt.C3D(bW * 0.5 + w * 0.5, 0.5 * h), pt.C3D(bW * 0.5 + w * 0.5 + 5 * scale), ref ext, scale, (0.5 * h * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimAli(db, pt.C3D(bW * 0.5 + w * 0.5, 0.5 * h), pt.C3D(bW * 0.5 + w * 0.5, 0.5 * h + guardrail_height), pt.C3D(bW * 0.5 + w * 0.5 + 5 * scale), ref ext, scale, (guardrail_height * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
                #endregion

                bW = bridgeW * 10;
                if (isReinforced)
                {
                   
                    DimPloter.AddMultiMLeader(db, pt.C2D(bW * 0.5 +w * 0.25, -divHeight), pt.C2D(bW * 0.5 + w * 0.5 + 2 * scale, -divHeight- h * 0.5 -2 * scale), pt.C2D(bW * 0.5 + w * 0.5 + 2 * scale, -divHeight - h * 0.5 - 2 * scale), reinforced_straight_web_bar, ref ext, scale);

                    DimPloter.AddMultiMLeader(db, pt.C2D(-bW * 0.25, -divHeight-0.25*h1), pt.C2D(-bW * 0.25 + 1 * scale, -divHeight - h * 0.5 - 8 * scale), pt.C2D(-bW * 0.25 + 1 * scale, -divHeight - h * 0.5 - 8 * scale), reinforced_diagonal_brace, ref ext, scale);
                }
                else
                {
                    DimPloter.AddMultiMLeader(db, pt.C2D(bW * 0.5 + w * 0.25, -divHeight), pt.C2D(bW * 0.5 + w * 0.5 + 2 * scale, -divHeight - h * 0.5 - 2 * scale), pt.C2D(bW * 0.5 + w * 0.5 + 2 * scale, -divHeight - h * 0.5 - 2 * scale), straight_web_bar, ref ext, scale);
                    DimPloter.AddMultiMLeader(db, pt.C2D(-bW * 0.25, -divHeight - 0.25 * h1), pt.C2D(-bW * 0.25 + 1 * scale, -divHeight - h * 0.5 - 8 * scale), pt.C2D(-bW * 0.25 + 1 * scale, -divHeight - h * 0.5 - 8 * scale), diagonal_brace, ref ext, scale);
                }
                pt = GeTools.DivPoint(pt1.C3D(), pt2.C3D(), 3,true).C2D();
                if (isReinforced)
                {
                    DimPloter.AddMultiMLeader(db, pt.C2D(0, 0), pt.C2D(2 * scale + 0.5 * w, 0.5 * h1 + 1 * scale), pt.C2D(2 * scale + 0.5 * w, 0.5 * h1 + 1 * scale), reinforced_web_bar, ref ext, scale);
                }
                else
                {
                    DimPloter.AddMultiMLeader(db, pt.C2D(0, 0), pt.C2D(2 * scale + 0.5 * w, 0.5 * h1 + 1 * scale), pt.C2D(2 * scale + 0.5 * w, 0.5 * h1 + 1 * scale), web_bar, ref ext, scale);
                }
            }
        }
    }
}
